连续两次正向预测失败,但每次都成功

问题描述 投票:0回答:1

我正在尝试编写一个 Java 8 风格的正则表达式,它会查找两个不同的静态字符串以任意顺序出现在多行文本文件中。这是我正在搜索的文字:

exception data-corruption buffer truncate
exception data-corruption buffer log
exception crashinfo file flash:crashinfo
exception crashinfo buffersize 32
exception crashinfo maximum files 1
no exception crashinfo dump garbage-detector
no monitor environment temperature notifies
monitor environment temperature syslog
no monitor environment temperature history
monitor environment temperature low -25

在这种情况下,我使用这个正则表达式:

(?=crashinfo buffersize)(?=crashinfo file)

我希望这能够匹配,因为两个字符串都在文件中,但发生的情况是,任一前瞻本身都会成功,但两者一起都会失败。

我只搜索了

(?=crashinfo buffersize)
并且匹配。我还只搜索了
(?=crashinfo file)
,它也匹配。我预计将两者放在一起也会匹配,因为每个都是孤立匹配的。

我在其他情况下使用过类似的结构,并且效果很好。在此文件中,每个单独的前瞻都会单独成功,但如果我将它们一起使用,它们就会失败。我被困住了。谁能告诉我我做错了什么?

java regex regex-lookarounds
1个回答
0
投票

我的正则表达式:

String regex = "(?s)(?=.*crashinfo buffersize)(?=.*crashinfo file)";
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.