字符串的正则表达式-流利的
Regex for a string- fuentd
2016-10-21 01:10:27.513|main|INFO|125.0.225.25|gdtl01db7i7h|{"instanceName":"testinstance","applicationId":"ABS3PP","transactionStatus":"C","responseCode":"0","responseDescription":"Success","initiatedTimestamp":"2016-09-19 00:00:00.0","elapsedTime":"44400.0","clientApp":"ServiceGateway~368","clientIp":"35.23.89.235","cluster":"P27C","httpMethod":"POST","requestURL":"/test/ctn"}
我需要为上面的字符串写一个正则表达式,比如
/^(?<eventtimestamp>)\|(?<TYPE>)\|(?<LOGLEVEL>)\|(?<IPaddress>)\|(?<HOSTNAME>)\| (?<message>.*)$/
在我看来你可以使用
^(?<eventtimestamp>[\d:. -]+)\|(?<TYPE>[a-zA-Z]+)\|(?<LOGLEVEL>[a-zA-Z]+)\|(?<IPaddress>[\d.]+)\|(?<HOSTNAME>[^|]+)\|(?<message>.*)$
详情:
^
- string/line 的开始
(?<eventtimestamp>[\d:. -]+)
- 1+ 位,:
,.
,空格,-
\|
- 文字 |
(?<TYPE>[a-zA-Z]+)\|
- 1+ 个字母和一个 |
(?<LOGLEVEL>[a-zA-Z]+)\|
- 1+ 个字母和一个 |
(?<IPaddress>[\d.]+)\|
- 1+ 位数字或 .
和一个 |
(?<HOSTNAME>[^|]+)\|
- |
和 |
以外的 1 个以上字符
(?<message>.*)
- 任何 0+ 个字符直到...
$
- string/line. 结束
2016-10-21 01:10:27.513|main|INFO|125.0.225.25|gdtl01db7i7h|{"instanceName":"testinstance","applicationId":"ABS3PP","transactionStatus":"C","responseCode":"0","responseDescription":"Success","initiatedTimestamp":"2016-09-19 00:00:00.0","elapsedTime":"44400.0","clientApp":"ServiceGateway~368","clientIp":"35.23.89.235","cluster":"P27C","httpMethod":"POST","requestURL":"/test/ctn"}
我需要为上面的字符串写一个正则表达式,比如
/^(?<eventtimestamp>)\|(?<TYPE>)\|(?<LOGLEVEL>)\|(?<IPaddress>)\|(?<HOSTNAME>)\| (?<message>.*)$/
在我看来你可以使用
^(?<eventtimestamp>[\d:. -]+)\|(?<TYPE>[a-zA-Z]+)\|(?<LOGLEVEL>[a-zA-Z]+)\|(?<IPaddress>[\d.]+)\|(?<HOSTNAME>[^|]+)\|(?<message>.*)$
详情:
^
- string/line 的开始
(?<eventtimestamp>[\d:. -]+)
- 1+ 位,:
,.
,空格,-
\|
- 文字|
(?<TYPE>[a-zA-Z]+)\|
- 1+ 个字母和一个|
(?<LOGLEVEL>[a-zA-Z]+)\|
- 1+ 个字母和一个|
(?<IPaddress>[\d.]+)\|
- 1+ 位数字或.
和一个|
(?<HOSTNAME>[^|]+)\|
-|
和|
以外的 1 个以上字符
(?<message>.*)
- 任何 0+ 个字符直到...$
- string/line. 结束