【问题标题】:Splunk regex to match part of url stringSplunk 正则表达式以匹配部分 url 字符串
【发布时间】:2023-09-24 02:17:02
【问题描述】:

我正在尝试使用 Splunk 搜索特定 url 的所有基本路径实例(然后可能将其绘制在图表上)。

以下是一些示例 url 和我想要匹配的部分:

http://some-url.com/first/  # match "first"
http://some-url.com/first/second/ # match "first"
http://some-url.com/first/second/third/  # match "first"

这是我正在使用的正则表达式,效果很好:

http:\/\/some-url\.com\/(.*?)\/

我的 Splunk 搜索应该是什么来提取所需的文本?这在 Splunk 中是否可行?

【问题讨论】:

    标签: regex splunk


    【解决方案1】:

    假设总是com

    使用rex

    index= and other stuff | rex field=(if not _raw) "\.com/(?<match> \w+)/" | table match
    

    【讨论】:

      【解决方案2】:

      要匹配任何 URL(.com 与否),您可以使用以下命令。

      index=... | rex field=_raw "http(s)?://[^/]+/(?<match>[^/]+)"
      

      这将匹配诸如

      之类的东西
      http://splunk.com/first/
      https://simonduff.net/first/
      https://splunk.com/first/middle/last
      https://splunk.com/first
      

      【讨论】: