REQ:协助Splunk - Rex Query

问题描述 投票:2回答:1

我在rex查询中遇到一些问题,其中单个数字日期呈现的结果不正确,但是两位数的日期提供了正确的结果。

这些是我要查询的日志条目:

Mar  7 14:24:29 10.52.176.215 Mar  7 12:24:29 963568 - Melbourne details-cable-issue - vdvfvfv

Mar 20 09:52:55 10.52.176.215 Mar 20 07:52:55 963569 - Brisbane cable-issue

这是查询:

^(?:[^ \n]* ){7}(?P<extension>[^ ]+)[^\-\n]*\-\s+(?P<location>\w+)

对于Mar 7条目,我的查询给了我组扩展“7”,而我的Mar 20条目给了我组扩展名“963569”,这是正确的。

有人可以对我的查询有所了解,以确认单个和两位数的日期吗? #7 vs 20

谢谢大家:)

regex splunk rex
1个回答
0
投票

在第一个字符串中有几个连续的空格(它们看起来像填充空格),因为你只匹配(?:[^ \n]* )中的一个空格,你会得到不匹配。

我建议在第一组中匹配1个或多个空格并调整限制量词:

^(?:[^ \n]* +){5}(?P<extension>[^ ]+)[^-\n]*-\s+(?P<location>\w+)
            ^  ^

regex demo

© www.soinside.com 2019 - 2024. All rights reserved.