【发布时间】:2017-03-21 10:18:26
【问题描述】:
我有两种不同格式的日志行,你可以用这个site做测试
我需要在下面的行中保留可选的客户端部分,如果存在则结束,否则它会忽略
\[(?<date>[^\]]*)\] \[(?<level>[^\]]*)\] \[(?<pid-tid>[^\]]*)\] (\[(?<client>[^\]]*)\]) (?<message>[^\]]*)
日志行 - 无客户端
[2016 年 1 月 18 日星期一 21:55:58.239970] [proxy_http:error] [pid 2769:tid 140041068427008] AH01114:HTTP:无法连接到后端:xx.xxx.xx.xx
日志行 - 与客户
[2016 年 1 月 18 日星期一 21:55:58.239970] [proxy_http:error] [pid 2769:tid 140041068427008] [client xx.xxx.x.xx:10723] AH01114:HTTP:无法连接到后端:xx .xxx.xx.xx
我尝试过 (.*?clientsection) -> 0 个或多个匹配项
\[(?<date>[^\]]*)\] \[(?<level>[^\]]*)\] \[(?<pid-tid>[^\]]*)\] (.*?(\[(?<client>[^\]]*)\])) (?<message>[^\]]*)
但它不起作用
【问题讨论】:
-
检查this demo。