我的 jenkins 控制台输出中有 2 行,我正在尝试使用 java regex
使用 Jenkins Text Finder 插件
捕获它们
我的控制台输出如下所示:
**The total percentage is:70%
Student passed the exam**
我尝试过的java regex
是:
The total percentage is:([0-9]\d|\d{3,})%(\n|$)Student passed the exam
代替 (\n|$)
来拾取下一个新行,我尝试了 [\s\S]
和 (.|\n )
。但没有任何作用。
有人可以帮我解决这个问题吗?
编辑:
当找到其中之一或同时找到两条线时,构建应该不稳定。 A|B|AB
的含义
最佳答案
我认为你可以使用以下正则表达式:
^The total percentage is:[0-9]{1,2}(\.[0-9]{1,})?%|Student passed the exam$
由于任一句子的存在都表示控制台输出中的匹配项,因此您无需检查两者。因此,这里可以使用带有交替的正则表达式。
以下是与百分比匹配的模式的说明:
[0-9]{1,2} one or two leading digits
(
\. followed by an (optional) decimal point
[0-9]{1,} followed by one or more digits after that (again optional)
)?
% followed by a percent sign
此处演示:
Regex101
关于Jenkins Text Finder 中的 Java 正则表达式匹配 2 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41669794/