【问题标题】:How to capture type of events in fields based on single event type?如何根据单个事件类型捕获字段中的事件类型?
【发布时间】:2019-01-29 14:15:43
【问题描述】:

1) 如何使用正则表达式捕获 INFO/ERROR/WARN 事件?

2) 如何使用正则表达式捕获不包括 INFO/ERROR/WARN 事件的其余事件?

示例日志如下所示:

[30/07/18 17:42:00:492 XXX] 00000056 SystemOut     O 30 Jul 2017 17:42:00:492 [INFO] [xxxxxx] [] xxxxx - The total xxx is 411116 and the memory available is 2638295816.
[30/07/17 17:42:00:492 XXX] 00000056 SystemOut     O 30 Jul 2017 17:42:00:492 [ERROR] [xxxxxx] [] xxxxxxx - The total xxx is 111111111 and the memory available is 2638295816.
[30/07/17 17:42:00:492 XXX] 00000056 SystemOut     O 30 Jul 2017 17:42:00:492 [WARN] [xxxxxx] [] xxxxxx - The total xxx is 1111111 and the memory available is 2638295816.
[30/07/17 15:37:42:379 XXX] 00001db5 LdapConnectio I xxx.xxx.xx.xx.xxxxx.xxxx.xxxxxxxxxx  reCreateDirContext(String errorMessage) xxxxxxxxx The user registry is now connected to 'xxxxxxxxxxxxxx' LDAP Server.
[30/07/17 15:33:59:281 XXX] 0000xxxx0 SystemOut O Into the constructor of xxxxx

【问题讨论】:

    标签: regex regex-negation regex-lookarounds


    【解决方案1】:

    1) ^.*\[(INFO|ERROR|WARN)\].*$ 所有人

    或

    ^.*\[INFO\].*$ 仅用于INFO

    2) ^(?!.*\[(INFO|ERROR|WARN)\].*).*$ 对于所有其他人(这仅适用于 PCRE)

    【讨论】:

    • 嗨 #CrafterKolyan 感谢您的回复,您能否提供正则表达式以将这些文件捕获在类似 xxxx(?Pxxxx)xxxx 的变量中,因为我需要像这样提取它们
    • 修改为捕获警告/信息/错误,例如 ^.*[(?PINFO|ERROR|WARN)].*$ 正在工作,但是当尝试捕获不存在信息的字段时/error/warn 通过这样修改 ^(?!.*[(?PINFO|ERROR|WARN)].*).*$ 不起作用
    • @PrincceRajesh 我认为您需要使用^.*\[(?P<name>INFO|ERROR|WARN)\].*$ 和^(?!.*\[(?P<name>INFO|ERROR|WARN)\].*).*$(将[ 更改为\[ 和] 为\]),因为实际上[ 和@987654332 @ 是正则表达式的语法
    猜你喜欢
    • 1970-01-01
    • 2011-08-24
    • 2020-09-04
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    相关资源
    最近更新 更多