如:
<a href="http://www.sina.com.cn/hhh.aspx" target="_top"><font style="font-size:12px;color:blue"><b>新浪网HHH.asp</b></font></a><a href="http://www.第二个链接">第一个连续的链接</a>
我想得到这个链接中的(http://www.sina.com.cn/hhh.aspx)和(新浪网HHH.asp)
现在有个问题是:一个未知的html文件中有N多个这样的链接,要把这N多个链接的文字和链接地址取出来,并且每个链接形成一条记录
上面的两个链接应该变成
http://www.sina.com.cn/hhh.aspx 新浪网HHH.asp
http://www.第二个链接 第一个连续的链接
要用正则表达式的解出,小弟知道CSDN上高手如云,特发此贴,请老大们赐教,谢谢!
Regex r;
Match m;
int tempCount=0;
r = new Regex("(?<2>(?:\\<(a|A))\\s*href=*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))[^\\<\\>]*\\>[^(\\<\\/a>)]*(?:\\<\\/(a|A)\\>))",RegexOptions.IgnoreCase|RegexOptions.Compiled);
for (m = r.Match(inputString); m.Success; m = m.NextMatch())
{
Console.WriteLine("Found href " + m.Groups[1] + " at " + m.Groups[1].Index+"\n");
tempCount++;
}