【发布时间】:2016-11-28 10:59:43
【问题描述】:
我正在尝试使用 onigurama 正则表达式库(在 Logstash 中)使用否定的后视来捕获日志文件中的一行,但它似乎仍然与它不应该匹配的行匹配。我试图只匹配顶级异常,而不是以 Caused By:
开头的异常有人帮我写了这个
在 Rubular 上测试 http://rubular.com/r/N3AzySNHiS
经过测试的正则表达式
^(?<!Caused by: ).*?Exception
(?<!^Caused by: ).*?Exception
消息:
2016-11-15 05:19:28,801 ERROR [App-Initialisation-Thread] appengine.java:520 Failed to initialize external authenticator myapp Support Access || appuser@vm23-13:/mnt/data/install/assembly app-1.4.12@cad85b224cce11eb5defa126030f21fa867b0dad
java.lang.IllegalArgumentException: Could not check if provided root is a directory
at com.myapp.jsp.KewServeInitContextListener$1.run(QServerInitContextListener.java:104)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.file.NoSuchFileException: fh-ldap-config/
at com.upplication.s3fs.util.S3Utils.getS3ObjectSummary(S3Utils.java:55)
at com.upplication.s3fs.util.S3Utils.getS3FileAttributes(S3Utils.java:64)
Logstash 结果
"exception" => "Caused by: java.nio.file.NoSuchFileException"
【问题讨论】:
-
试试
^(?!Caused by: ).*?Exception,或^(?!Caused by:)(?<exception>.*?Exception) -
感谢Wiktor的回复,第一个返回
"exception" => " at java.lang.Thread.run(Thread.java:745)\nCaused by: java.nio.file.NoSuchFileException",第二个返回2个结果` "exception" => [ [0] " at java.lang.Thread.run(Thread.java :745)\n引起:java.nio.file.NoSuchFileException",[1]" at java.lang.Thread.run(Thread.java:745)\n引起:java.nio.file.NoSuchFileException"`跨度> -
我怀疑有一些设置使正则表达式中的
.符号与换行符匹配。或者其他一些选项,如忽略空格是 ON。请检查是否在任何地方打开了多行模式。另外,一个好主意是检查^(?!Caused\ by:)(?<exception>[^\r\n]*?Exception)regex -
谢谢@WiktorStribiżew!最后一个正则表达式就像一个魅力,但返回了 2 个结果
"exception" => [ [0] "com.fredhopper.frontend.view.ViewCreationException", [1] "com.fredhopper.frontend.view.ViewCreationException"它是否以某种方式匹配同一行两次? -
不,再次,这是我们上次讨论的内容,我不知道什么设置可能会返回两次捕获的文本。
标签: regex logstash regex-lookarounds logstash-grok oniguruma