正则表达式字符串fuentd

时间:2016-12-15 08:34:09

标签: regex fluentd

  

2016-10-21 01:10:27.513 | main | INFO | 125.0.225.25 | gdtl01db7i7h | {" instanceName":" testinstance"," applicationId&#34 ;:" ABS3PP""的TransactionStatus":" C"" responseCode":" 0"&#34 ; responseDescription":"成功"," initiateTimestamp":" 2016-09-19 00:00:00.0"," elapsedTime&#34 ;:" 44400.0"" clientApp":" ServiceGateway〜368"" clientIp":" 35.23.89.235&# 34;,"簇":" P27C""列举HTTPMethod":" POST"" requestURL":&# 34 /测试/箱"}

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

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

1 个答案:

答案 0 :(得分:1)

在我看来,你可以使用

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

请参阅regex demo

<强>详情:

  • ^ - 字符串/行
  • 的开头
  • (?<eventtimestamp>[\d:. -]+) - 1位数,:.,空格,-
  • \| - 文字|
  • (?<TYPE>[a-zA-Z]+)\| - 1+个字母和|
  • (?<LOGLEVEL>[a-zA-Z]+)\| - 1+个字母和|
  • (?<IPaddress>[\d.]+)\| - 1位数或.|
  • (?<HOSTNAME>[^|]+)\| - 除||以外的1个字符
  • (?<message>.*) - 任何0 +字符到......
  • $ - 字符串/行的结尾。