【问题标题】:Regex for a string- fuentd流利的字符串的正则表达式
【发布时间】:2016-12-15 08:34:08
【问题描述】:

2016-10-21 01:10:27.513|main|INFO|125.0.225.25|gdtl01db7i7h|{"instanceName":"testinstance","applicationId":"ABS3PP","transactionStatus":"C"," responseCode":"0","re​​sponseDescription":"Success","initiatedTimestamp":"2016-09-19 00:00:00.0","elapsedTime":"44400.0","clientApp":"ServiceGateway~368", "clientIp":"35.23.89.235","cluster":"P27C","httpMethod":"POST","re​​questURL":"/test/ctn"}

我需要为上面的字符串写一个正则表达式

/^(?<eventtimestamp>)\|(?<TYPE>)\|(?<LOGLEVEL>)\|(?<IPaddress>)\|(?<HOSTNAME>)\| (?<message>.*)$/

【问题讨论】:

    标签: regex fluentd


    【解决方案1】:

    在我看来你可以使用

    ^(?<eventtimestamp>[\d:. -]+)\|(?<TYPE>[a-zA-Z]+)\|(?<LOGLEVEL>[a-zA-Z]+)\|(?<IPaddress>[\d.]+)\|(?<HOSTNAME>[^|]+)\|(?<message>.*)$
    

    regex demo

    详情

    • ^ - 字符串/行的开始
    • (?&lt;eventtimestamp&gt;[\d:. -]+) - 1+ 位,:.,空格,-
    • \| - 文字 |
    • (?&lt;TYPE&gt;[a-zA-Z]+)\| - 1+ 个字母和一个 |
    • (?&lt;LOGLEVEL&gt;[a-zA-Z]+)\| - 1+ 个字母和一个 |
    • (?&lt;IPaddress&gt;[\d.]+)\| - 1+ 位或 .|
    • (?&lt;HOSTNAME&gt;[^|]+)\| - 除|| 之外的1+ 个字符
    • (?&lt;message&gt;.*) - 任何 0+ 字符直到...
    • $ - 字符串/行结束。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 2012-10-11
      相关资源
      最近更新 更多