<div style="display:none;">
<a href="http://ent.qq.com/a/20070618/000005.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06181.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
<div style="display:none;">
<a href="http://ent.qq.com/a/20070618/000013.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06182.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
<div style="display:none;">
<a href="http://ent.qq.com/a/20070618/000020.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06183.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
<div style="display:none;"><a href="http://ent.qq.com/a/20070618/000017.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06184.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>

<div style="display:block;">
<a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06185.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>这只是一个页面的一部分代码, 但 <a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06185.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
是唯一的,求这里的网址和图片,网址和图片是对应的

解决方案 »

  1.   

    可以先截取<a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank">
    然后在截取http://ent.qq.com/a/20070618/000009.htm
    我这是比较笨的方法吧...刚学正则,等更好的方法
      

  2.   

    try
    MatchCollection mc = Regex.Matches(yourStr, @"<a\s+href=(['""]?)(?<url>[^'""\s>]*)\1?[^>]*><img\s+src=(['""]?)(?<img>[^'""\s>]*)\2?[^>]*>", RegexOptions.IgnoreCase);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups["url"].Value + "\n";
        richTextBox2.Text += m.Groups["img"].Value + "\n";
    }是取出多个吗,不太明白你说的唯一性
      

  3.   

    是取多个, 就是网址和图片的  <a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06185.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    这是一组
      

  4.   

    这个我试过了用你给的数据:string strPattern=@"<a(\s.*?)href=\042(?<Link>[^\042]+)(.*)<img src=\042(?<Text>[^\042]+)(.*)</a>";MatchCollection Matches=Regex.Matches(strPage,strPattern,RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);foreach(Match NextMatch in Matches)
    {
    string strURLText=NextMatch.Groups["Text"].Value +"|"+ NextMatch.Groups["Link"].Value;
    Response.Write(strURLText + "<br>");

    }
      

  5.   

    to:lxcnn(过客) <a\s+href=(['""]?)(?<url>[^'""\s>]*)\1?[^>]*>

    <a\s+href=['"]?(?<url>[^'"\s>]*)\1?[^>]*>
    等价的不?
    貌似这里['""]多了个"
      

  6.   

    http://ent.qq.com/这一页, 提取<div style="display:none;">
    <a href="http://ent.qq.com/a/20070618/000005.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06181.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;">
    <a href="http://ent.qq.com/a/20070618/000013.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06182.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;">
    <a href="http://ent.qq.com/a/20070618/000020.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06183.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;"><a href="http://ent.qq.com/a/20070618/000017.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06184.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>

    <div style="display:block;">
    <a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06185.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    这段代码的 网址和图片地址
      

  7.   

    <a\s+href=(['""]?)(?<url>[^'""\s>]*)\1?[^>]*>

    <a\s+href=['"]?(?<url>[^'"\s>]*)\1?[^>]*>
    等价的不?
    貌似这里['""]多了个"---------应该是字符串里面的转义吧?
      

  8.   

    <a\s[^>]*href=(['"]*)(?<url>[^"'\s]+)\1\starget=['"]*_blank["']*><img\s[^>]*src=(["']*)(?<src>[^"'\s]+)\2[^>]*onMouseOver="clearAuto\(\);"\s*onMouseOut="SetAuto\(\)"[^>]*>
    ..........我的
      

  9.   

    回复人:ra2_fang(先知) ( 二级(初级)) 信誉:100这个是仿的先知?
      

  10.   

    firsk(杰少)
    回复人:ra2_fang(先知) ( 二级(初级)) 信誉:100这个是仿的先知?
    ----------------------
    啥仿的先知??????????
      

  11.   

     回复人:sibyle(先知) ( 五级(中级)) 信誉:100
    这里还有一个的晕。。
      

  12.   

    哦,呵呵 先知是farseer啊
    WAR3里面的,我玩ORC
      

  13.   

    哦,只要那几个的,这样试试吧string yourStr = ...............;
    MatchCollection mc = Regex.Matches(yourStr, @"<div style=""display:(none|block);"">\s*<a\s+href=(['""]?)(?<url>[^'""\s>]*)\1?[^>]*><img\s+src=(['""]?)(?<img>[^'""\s>]*)\2?[^>]*>", RegexOptions.IgnoreCase);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups["url"].Value + "\n";  //网址
        richTextBox2.Text += m.Groups["img"].Value + "\n";  //图片地址
    }
      

  14.   

    要这里的<a href="http://ent.qq.com/a/20070618/000005.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06181.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;">
    <a href="http://ent.qq.com/a/20070618/000013.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06182.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;">
    <a href="http://ent.qq.com/a/20070618/000020.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06183.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    <div style="display:none;"><a href="http://ent.qq.com/a/20070618/000017.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06184.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>

    <div style="display:block;">
    <a href="http://ent.qq.com/a/20070618/000009.htm" target="_blank"><img src="http://mat1.qq.com/ent/upday200703/06185.jpg" width="328" height="240" border="0" onMouseOver="clearAuto();" onMouseOut="setAuto()" /></a></div>
    这段代码的 网址和图片地址
      

  15.   

    谢了,问题解决了, 谢了lxcnn(过客)
      

  16.   

    lxcnn(过客)的方法不错,帮你测试了!