草堆:
<test 00>
Don't match
</test>
asdasdasdasdasdasdasda
asdasdasdasdasdasdasda
<test 01>
Don't match
</test>
asdasdasdasdasdasdasda
asdasdasdasdasdasdasda
<test 10>
MATCH ME
</test>
asdasdasdasdasdasdasda
asdasdasdasdasdasdasda
<test 11>
Don't match
</test>
目标:我正在尝试匹配
<test 10>
MATCH ME
</test>
我最终使用的正则表达式是<test[^>]*?>(.|\n)+?MATCH ME(.|\n)+?</test>
。我的问题是我的表达式返回以下
<test 00>
Don't match
</test>
asdasdasdasdasdasdasda
asdasdasdasdasdasdasda
<test 01>
Don't match
</test>
asdasdasdasdasdasdasda
asdasdasdasdasdasdasda
<test 10>
MATCH ME
</test>
答案 0 :(得分:1)
<test[^>]*>(?:(?!<test[^>]*>)[\S\s])*MATCH ME(.|\n)+?<\/test>
或强>
使用否定前瞻以及DOTALL修饰符(?s)
,
(?s)<test[^>]*>(?:(?!<test[^>]*>).)*?MATCH ME.+?<\/test>