用于捕获 Maven 测试输出的正则表达式
当我运行测试时,我有这个 Maven 输出:
...
[INFO]
[ERROR] Tests run: 77, Failures: 0, Errors: 2, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42:09 min
[INFO] Finished at: 2022-02-25T10:40:21Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project ***-***-******-*****: There are test failures.
[ERROR]
...
我想用 Regex 或其他方式捕获这一行:
Tests run: 77, Failures: 0, Errors: 2, Skipped: 0
我不需要准确地捕获它,但至少需要捕获一般区域,因为每个测试类都会生成自己的测试摘要 由于
到目前为止,我想出的正则表达式是:
((?<=\[ERROR\]).*\n).*((?=BUILD).*\n)
某种原因,它不起作用。
我该怎么做?
I have this Maven output when I run my tests:
...
[INFO]
[ERROR] Tests run: 77, Failures: 0, Errors: 2, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42:09 min
[INFO] Finished at: 2022-02-25T10:40:21Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project ***-***-******-*****: There are test failures.
[ERROR]
...
I want to capture this line with Regex or otherwise:
Tests run: 77, Failures: 0, Errors: 2, Skipped: 0
I don't need to capture it exactly, but at least the general area, as each test class produces its own test summary of tests run, passed etc.
The RegEx I have come up with so far is:
((?<=\[ERROR\]).*\n).*((?=BUILD).*\n)
Which doesn't work for some reason.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以
在部分中使用模式匹配:
\[ERROR\]
匹配[ERROR]
(.*)
捕获组 1,匹配整行(?:
非捕获组\n
匹配换行符(?!
断言右侧的内容不是负向前瞻.* BUILD\b
匹配行中的BUILD
|
或者\[ERROR]
匹配[ERROR]
)
关闭前瞻.*
匹配整行)*
关闭非捕获组并可选择重复\n .* BUILD\b
匹配换行符并 的行BUILD
Regex demoYou could use
In parts, the pattern matches:
\[ERROR\]
Match[ERROR]
(.*)
Capture group 1, match the whole line(?:
Non capture group\n
Match a newline(?!
A negative lookahead to assert what is to the right is not.* BUILD\b
MatchBUILD
in the line|
Or\[ERROR]
Match[ERROR]
)
Close the lookahead.*
Match the whole line)*
Close non capture group and optionally repeat\n.* BUILD\b
Match a newline and the line withBUILD
Regex demo