Splunk PCRE 组名称问题

发布于 2025-01-09 21:47:27 字数 166 浏览 1 评论 0原文

我正在尝试在 PCRE 组名称中添加一个空格。不知道该怎么做。例如:

rex field=_raw "Time take = (?<"TimeInMillisecs">[^\s^\D+]+)

在上面,我需要组名称为“Time in Millisecs”。如何更改上面的表达式?

I am trying to add a space to the PCRE group name.Not sure how to do so.For ex:

rex field=_raw "Time taken = (?<"TimeInMillisecs">[^\s^\D+]+)

In the above,I need the group name to be "Time in Millisecs".How do I change the above expression?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羞稚 2025-01-16 21:47:28

不。使用 Splunk 字段名称中的空格可能会出现问题。最好使用压缩名称,然后在查询末尾使用 rename 命令更改为所需的显示名称。

rex field=_raw "Time taken = (?<TimeInMillisecs>[^\s^\D+]+)
| rename TimeInMillisecs as "Time in Ms"

Don't. Working with spaces in Splunk field names can be problematic. It's best to use the compressed name and then use a rename command at the end of the query to change to the desired display name.

rex field=_raw "Time taken = (?<TimeInMillisecs>[^\s^\D+]+)
| rename TimeInMillisecs as "Time in Ms"
南烟 2025-01-16 21:47:28

正则表达式中的几个单词: [^\s^\D+]+ 匹配除空格、^、非数字和 + 之外的一个或多个字符 字符。

请注意, \D 匹配任何空格、^+ 字符,因为它们是非数字字符,因此 [^\s^ \D+]+ 等于[^\D]+。正如您所看到的,“非数字字符之外的任何一个或多个字符”实际上与“一个或多个数字字符”相同。

因此,为了使您的正则表达式没有歧义,您可以使用:

rex field=_raw "Time taken = (?<TimeInMillisecs>\d+)
| rename TimeInMillisecs as "Time In Millisecs"

A couple of words on your regex: [^\s^\D+]+ matches one or more chars other than whitespace, ^, non-digit and + chars.

Note that \D matches any whitespaces, ^ and + chars since they are non-digit chars, so [^\s^\D+]+ is equal to [^\D]+. And as you can see, "any one or more chars other than non-digit chars" is actually the same as "one or more digit chars".

So, to make your regex free from ambiguity, you can use:

rex field=_raw "Time taken = (?<TimeInMillisecs>\d+)
| rename TimeInMillisecs as "Time In Millisecs"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文