网上搜了很多有关提取HTML源码中的超链接的正则,不过有些是没有完整的获取超连接。
能给我提供你们认为最好的一个正则表达式。。

解决方案 »

  1.   


    Regex re = new Regex(@"(?is)(?<=<a[^>]*href=\s*[""']).*?(?=[""'][^>]*>)", RegexOptions.None);
    MatchCollection mc = re.Matches("你要提取的");
    foreach (Match ma in mc)
    {
       //ma.Value是你要的
    }
      

  2.   

    <a href="http://www.nur.cn/news.php">新闻</a>  
    不要标签,只要提取它的http://www.nur.cn/news.php部分,
    我的意思是在整个html源码中抽取这样的超链接,href开头的
      

  3.   


     string htmsStr = @"<div class=""fans_top"" id=""weibo_head"">
    <a href=""http://baidu.com/"" target=""_blank"">评论(0)</a>
    <div>dddd</div>
    </div><div class=""ddd"" id=""ccc"">
    <a href=""http://baidu.com/"" target=""_blank"">评论(20)</a>
    <a href=""http://baidu.com/"" target=""_blank"">评论(150)</a>
    </div>
    ";
                Regex re = new Regex("(?is)<a\\s*href=\"(?<html>(.*?))\"\\s*[^>]*>[^<]*</a>");
                MatchCollection mt = re.Matches(htmsStr);
                List<string> path = new List<string>();
                foreach (Match m in mt)
                {
                    path.Add(m.Groups["html"].Value);//结果在path中
                }