如何编写正则表达式来替换没有链接文本的链接,如下所示:
<a href="http://www.somesite.com"></a>
与
<a href="http://www.somesite.com">http://www.somesite.com</a>
?
这就是我试图捕获匹配项的方法,但没有捕获到任何匹配项。我做错了什么?
string pattern = "<a\\s+href\\s*=\\s*\"(?<href>.*)\">\\s*</a>";
请您参考如下方法:
我不会使用正则表达式 - 我会使用 Html Agility Pack ,以及类似这样的查询:
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[.='']")) {
link.InnerText = link.GetAttribute("href");
}
