在日志中查找特定 pattern/text 的正则表达式

Regular Expression to find specific pattern/text in logs

我正在写 Python script 来过滤一些 log 文件,我想用常规 expressions/some 库过滤文本(preferred regex 因为我想避免依赖虚拟环境)。下面是我要查找的text/sentence:

Failed to find the annotation and the status of the test public void com.somename.qa.mobile.tests.somename.SomeTest.testSomeName(). The result is not deployed to Platform but we will proceed with further tests

此类行可能会在控制台日志中出现 20 次。我想找到这个的每个实例并为每个实例获取该方法名称somename.SomeTest.testSomeName()(最终我会收集所有名称并向自己发送电子邮件......但这是后面的部分)

到目前为止,我已经尝试过 '\[([^\]]+)\] somename.SomeTest.testSomeName() ([^ ]+)' 来找到模式。但我不擅长正则表达式,可能会做一些事情 extra/incorrect。

编辑:

Changing/expanding text/string 我想要一个正则表达式,它会为我找到:somename.SomeTest.testSomeName()

21:18:19 at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:170) 21:18:19 at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84) 21:18:19 at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92) 21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200) 21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153) 21:18:19 at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 21:18:26 2016-05-12 21:18:25.238 [ERROR] (1): Failed to find the annotation and the status of the test public void com.somename.qa.mobile.tests.somename.SomeTest.testSomeName(). The result is not deployed to Platform but we will proceed with further tests 21:18:26 somename.client.test.utilities.Platform.PlatformApiException: Platform API returned HTTP 400("Field :case_id is not a valid test case.") 21:18:26 at somename.client.test.utilities.platform.PlatformApiClient.sendRequest(PlatformApiClient.java:197) 21:18:26 at

你可以尝试使用以下 RE,

\w*.\w*.\w*\(\)

Demo here