[英]RegEx - Remove HTML hyperlinks based on the link text
我有一些带有HTML超链接的文本。 我要删除超链接,但只删除特定的超链接。
例如,我从这里开始:
This is text <a href="link/to/somewhere">Link to Remove</a> and more text with another link <a href="/link/to/somewhere/else">Keep this link</a>
我希望有:
This is text and more text with another link <a href="/link/to/somewhere/else">Keep this link</a>
我有这个RegEx表达式,
<a\s[^>]*>.*?</a>
...但是它匹配所有链接。
我需要在表达式中添加什么以仅匹配其中带有链接文本“ Remove”(例如)的链接?
提前致谢。
您可能会收到很多反馈,不要在HTML上使用正则表达式...但是如果您决定使用一个正则表达式,请尝试以下操作:
<a\s[^>]*>.*?Remove.*?</a>
这是链接文本中“删除”的位置。
$str=~/(.*)<a.*<\/a>([a-z ]+ <a.*<\/a>)/;
print "$1$2";
(。*?)<a。* [Rr]删除。*?a>(。*)
重建方式:$ 1 $ 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.