用一句正则表达式匹配出网上所有链接

需求:用一句表达式,就能匹配出网站上所有的链接,即匹配出url地址和标题。
例如:网页中有
……

1<a href="a.htm">abc</a>

……

匹配后得到的结果:
链接: a.htm
标题:abc
以www.sina.com.cn或news.sina.com.cn网站为例。
运行你的程序后,就能取出网站上可以抓取得到的所有链接。
---------------------------------------------------------------

1<a[\s\s]*?href=("(?<href>[^"]*)" ¦'(?<href>[^']*)' ¦(?<href>[^&gt;\s]*))[^&gt;]*?&gt;(?<title>[\s\S]*?)   
2  
3public static Regex regex = new Regex(   
4@"<a[\s\s]*?href=(""(?<href>[^""]*)"" ¦'(?<href>[^']*)' ¦(?<href" @"="" \+="">[^&gt;\s]*))[^&gt;]*?&gt;(?<title>[\s\S]*?)",   
5RegexOptions.IgnoreCase ¦ RegexOptions.Compiled);</title></href"></href></a[\s\s]*?href=(""(?<href></title></href></href></a[\s\s]*?href=("(?<href>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus