正则表达式,使用logstash grok过滤器提取文件路径的一部分 [英] Regular expression to extract part of a file path using the logstash grok filter
问题描述
我对正则表达式并不陌生,但我认为这里的人可能会给我提供宝贵的意见.我正在使用logstash grok
过滤器,在其中只能提供正则表达式
I am new to regular expressions but I think people here may give me valuable inputs. I am using the logstash grok
filter in which I can supply only regular expressions.
我有一个像这样的字符串
I have a string like this
/app/webpf04/sns882A/snsdomain/logs/access.log
我想使用正则表达式从字符串中获取sns882A
部分,该字符串是第三个"/"之后的子字符串,我该怎么做?
I want to use a regular expression to get the sns882A
part from the string, which is the substring after the third "/", how can I do that?
我只能使用正则表达式,因为grok仅接受正则表达式.可以使用正则表达式吗?
I am restricted to regex as grok only accepts regex. Is it possible to use regex for this?
推荐答案
是的,您可以使用正则表达式通过grok获取所需的内容:
Yes you can use regular expression to get what you want via grok:
/[^/]+/[^/]+/(?<field1>[^/]+)/
这篇关于正则表达式,使用logstash grok过滤器提取文件路径的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!