我的Jenkins任务搜索控制台输出以查看构建是否稳定。它搜索以下Java模式:exception|error|warning|Segmentation

我有一个包含-Werror=format-security的编译参数,因此Jenkins不应该匹配它。
我尝试使用此[exception|error|warning|Segmentation][^Werror],但仍在文本中找到Werror。我怎样才能使它不会因为编译参数而使我的构建不稳定?

最佳答案

您可以使用

^(?!.*Werror).*(?:exception|error|warning|Segmentation)


请参见RegexPlanet demo

细节


^-字符串开始
(?!.*Werror)-行上任何地方都不能有Werror子字符串
.*-尽可能多的除换行符以外的0+个字符
(?:exception|error|warning|Segmentation)-非捕获轮换组内的值之一。

关于java - Java正则表达式将模式与异常匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46539476/

10-15 22:30