使用正则表达式来查找HTML标记特定的字符串不 [英] Use regex to find specific string not in html tag
本文介绍了使用正则表达式来查找HTML标记特定的字符串不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个特定的正则表达式我试图用一些难度。我在寻找一个字符串的每个实例(对于我而言,我会说这是 MyString中的)的文件,除非它是一个标签,如:
I'm having some difficulty with a specific Regex I'm trying to use. I'm searching for every occurrence of a string (for my purposes, I'll say it's "mystring") in a document, EXCEPT where it's in a tag, e.g.
<a href="_mystring_">
应该不匹配,但
should not match, but
<a href="someotherstring">_mystring_</a>
应该匹配,因为它不是一个标签内(里面的意思里的&lt;和>标记)。我使用.NET的正则表达式功能这个问题,以及
Should match, since it's not inside a tag (inside meaning "inside the < and > markers") I'm using .NET's regex functions for this as well.
推荐答案
这应该做到这一点:
(?<!<[^>]*)_mystring_
它使用一个负的外观背后,以检查匹配的字符串不具有&LT;之前它没有相应的>
It uses a negative look behind to check that the matched string does not have a < before it without a corresponding >
这篇关于使用正则表达式来查找HTML标记特定的字符串不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文