正则一:
提取网页内所有的超链接地址和超链接文本
考虑的问题需全面一点比例:<a href='http://www.2elove.com'>方式一</a>
      <a href="http://www.2elove.com">方式二</a>
      <a href='list.aspx'>方式三</a>
      <a href="list.aspx">方式四</a>
      <a href='http://www.2elove.com' target="_blank">方式五</a>
      <a href="http://www.2elove.com" target='_blank'>方式六</a>
      <a href='list.aspx' target='_blank' class="link">方式七</a>
      <a href="list.aspx" target='_blank' class="link">方式七</a>等等,各种各样可能性的超链接,都要能提取。正则二:
<div class="list_page">    [1/2] <a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2' class="blue_link">下一页</a> <span class="blue_color">|</span><a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall' class="blue_link">剩下全文</a> </div>我想获得第二个<a href=' 与 '之间的内容,也就是n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall这个地址回答问题者大都是随意复制随意回复,请回复有价值的东西,谢谢! 

解决方案 »

  1.   

    <正则表达式必知必会>才100多页 啃了它把
      

  2.   

    取这些东西为什么要用正则直接取a标签的href和innerText不可以么?
    或者楼主再说具体些
      

  3.   

    Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
      MatchCollection mc = reg.Matches(Str);
      foreach (Match m in mc)
      {
      Console.WriteLine(m.Groups["url"].Value + "\n");
      Console.WriteLine(m.Groups["text"].Value + "\n");
      }  
      

  4.   

    @"(?si)(?<=<a\s+((?!href).)*href\s*=[^""']?)[^""'> ]*(?=[^<>]*>剩下全文</a>)
      

  5.   

    1.
    (?i)<a\b[^>]*?href=(['"\s]?)([^'"\s]+)\1[^>]*?>([^<>]+)</a>
    Groups[2]  Groups[3]就是你想要的2.(?i)<a\b[^>]*?href=(['"\s]?)([^'"\s]+)\1[^>]*?>剩下全文</a>
    Groups[2] 就是你想要的
      

  6.   

    正则一:
    (?is)<a\b[^>]*?href=(["'\s]*)(?<url>[^"']*?)\1[^>]*?>(?<innertext>(?:(?!</?a>\b).)*?)</a>
    结果:
    Groups["url"].Value
     Groups["innertext"].Value 
    正则二
    (?is)<a[^>]*?href=(["'\s]*)(?<url>[^"']*?)\1[^>]*?>(?:剩下全文)</a>
    Groups["url"].Value或者Groups[2].Value就是你要的
      

  7.   


    <div class="list_page"> [1/2] <a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2' class="blue_link">下一页</a> <span class="blue_color">|</span><a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall' class="blue_link">剩下全文</a> </div>这个不用正则,如果用string的方法该怎么获取这一段?
      

  8.   

    获取这一段n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall
      

  9.   


     string xstr = @"<div class=""list_page""> [1/2] <a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2' class=""blue_link"">下一页</a> <span class=""blue_color"">|</span><a href='n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall' class=""blue_link"">剩下全文</a> </div>";
                int ix = xstr.LastIndexOf(@"href='") + @"href='".Length;
                int iy = xstr.IndexOf(@"' class=""blue_link"">剩下全文</a> </div>");
                string ind = xstr.Substring(ix, iy - ix);//n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall
      

  10.   


    string tempStr = tempStr.Split('|')[1].Split('\'')[1];//n.aspx?CID=947&NID=SS,20120611,00003667&paid=1&kid=2&act=showall
      

  11.   

    正则一:href=[\"|'](.*?)[\"|']
    正则二:<div class=\"list_page\">.*?<a href='(.*?)'
      

  12.   

    {
         Match match = Regex.Match(html, string.Format(pattern, Regex.Escape(tag)),
             RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
         Console.WriteLine("--------begin {0}--------", tag);
         if (match.Success)
             Console.WriteLine(match.Value);
         else
             Console.WriteLine("o(╯□╰)o");
        Console.WriteLine("--------end {0}--------", tag);
    }
    试试我的方法