我想创建一个正则表达式来匹配包含我的域的所有href链接,并且我将最终删除这些链接。它运行良好,直到我遇到一个href链接,该链接在标记中包含另一个HTML标记。正则表达式匹配Href和删除
正则表达式声明:
(<a[^<]*coreyjansen\.com[^<]*>)([^"]*?)(<\/a>)
它在此声明,没有问题在href链接匹配
Need a lawyer? Contact <span style="color: #000000"><a
href="http://coreyjansen.com/">Random text is great</a> <a
href="http://coreyjansen.com/practice/family/">Corey is awesome</a></span>
这是无法同时匹配A HREF链接这一点声明:
<strong><a href="http://coreyjansen.com/"><img class="alignright size-full
wp-image-12" src="http://50h0.com/wp-content/uploads/2014/06/lawyers.jpg"
alt="lawyers" width="250" height="250" /></a>
我一直在试图玩忽视的字符集,没有运气。如果我删除被忽略的字符集,结果会发生什么,它会将匹配的两个链接(例如2作为一个匹配项)匹配。
改为使用您的编程语言的解析器! – Jan
为什么不通过HTML标签进行搜索,您为什么不在整个HTML代码中搜索您的域名,然后决定(手动)哪些链接属于哪个链接?这可以防止你需要一个解析器,也会捕获像JavaScript重定向,CSS链接,图像标签等东西。 – ctwheels