正则表达式 java 异常排除 "Caused by:"
regex java exception exclude "Caused by:"
我正在尝试从日志文件中捕获 Java 异常异常,但我想使用 Oniguruma 正则表达式版本 6.0.0[= 排除 "Caused by:" 字符串:
^.+Exception
returns:
"Caused by: java.nio.file.NoSuchFileException"
如何编写捕获异常名称但忽略它前面的 "Caused by: " 字符串的正则表达式。这将在 Grok Logstash
中使用
您可以使用 捕获 和以下模式:
^Caused\s*by:\s*(?<exception>[\w.]+)
(?<exception>[\w.]+)
命名的捕获组将匹配并捕获到组"exception"(创建具有相同名称的变量)1+字(字母,数字或下划线)或 .
个字符。
回答您的问题,检查并要求某些东西但将其排除在匹配之外,您可以使用环视:
(?<=^Caused by: ).*?Exception
见this Rubular demo. And below is a test at https://grokdebug.herokuapp.com/:
我正在尝试从日志文件中捕获 Java 异常异常,但我想使用 Oniguruma 正则表达式版本 6.0.0[= 排除 "Caused by:" 字符串:
^.+Exception
returns:
"Caused by: java.nio.file.NoSuchFileException"
如何编写捕获异常名称但忽略它前面的 "Caused by: " 字符串的正则表达式。这将在 Grok Logstash
中使用您可以使用 捕获 和以下模式:
^Caused\s*by:\s*(?<exception>[\w.]+)
(?<exception>[\w.]+)
命名的捕获组将匹配并捕获到组"exception"(创建具有相同名称的变量)1+字(字母,数字或下划线)或 .
个字符。
回答您的问题,检查并要求某些东西但将其排除在匹配之外,您可以使用环视:
(?<=^Caused by: ).*?Exception
见this Rubular demo. And below is a test at https://grokdebug.herokuapp.com/: