假设我有一个像这样的HTML标记:
<p>
<h1>Some header, which I don't want to match</h1>
Some text - match it.
<a href="some-file.html">Some link. Don't match neither href nor link text.<a>
<span>Some word, which needs to be matched</span>
</p>
简而言之,除了给定的html标签(及其属性)之外,我想在整个内容中匹配一些单词。在给定的示例中,我想排除h1和标签。
将'Some'替换为'Test'后的预期结果:
<p>
<h1>Some header, which I don't want to match</h1>
Test text - match it.
<a href="some-file.html">Some link. Don't match neither href nor link text.<a>
<span>Test word, which needs to be matched</span>
</p>
答案 0 :(得分:0)
您可以使用:<(a|h1)[^\>]*?>(some)[^\<]*?<\/\1>
来匹配包含some
的行和html标记之间的行。
检查一行是否不满足此正则表达式,然后用您所需的替换文本替换一些单词(如果有的话)。
<强> Demo 强>
说明: