【发布时间】:2018-01-09 11:13:10
【问题描述】:
我对 xpath 相当陌生,因此寻求一些帮助以匹配以下模式。我目前的尝试与我的预期不符。
//text()[1][contains(.,'wordToMatch') and not(self::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)
所有 3 个有效负载的预期结果是第一次出现术语 wordToMatch,它NOT 包裹在“a”标签内。
将实现此模式的最终语言是 Java。
请帮忙。
【问题讨论】: