【发布时间】:2018-01-08 18:04:31
【问题描述】:
我需要一个匹配第一次出现单词的正则表达式模式,不包含在“a”标签内,但可以包含在任何其他标签内标签。
即负前瞻以查看匹配的单词是否在 a' 标记内,如果是,则忽略并继续寻找有效匹配。
示例字符串
有效载荷 1:
<p>Sample 1 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some random text
to not be matched followed by wordToMatch, this should work.</p>
预期结果1:
wordToMatch ("Not the one inside of a' tags but the following one")
有效载荷 2:
<p>Sample 2 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some random text
to not be matched followed by <b>wordToMatch</b> this should work.</p>
预期结果 2:
wordToMatch ("The one inside of the b' tags")
有效载荷 3:
<p>Sample 3 <a href="shouldNotMatchWrappedInA">wordToMatch</a> some
random text to not be matched followed by wordToMatch followed by
further occurrences of wordToMatch which should not be matched.</p>
预期结果 3:
wordToMatch ("The second occurrence of the term")
请帮忙:'(
使用的语言是 Java
【问题讨论】:
-
改用一些
xpath查询 - 你的编程语言是什么? -
Java 但正在处理提取的 JCR 查询的响应。 XPATH 可能是一个选项。
标签: regex regex-lookarounds regex-group