regex - Splunk 正则表达式以匹配部分 url 字符串
问题描述
我正在尝试使用 Splunk 搜索特定 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 中是否可行?
解决方案
要匹配任何 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
推荐阅读
- c++ - 如何在 C++ 中删除这个 fpermissive 错误?
- css - 为什么下拉边框颜色不显示
- c++ - 为什么指针初始化后 cout 语句不起作用?
- java - 尝试在 docker 中运行 Spring Boot 应用程序时出现 java.lang.NoClassDefFoundError
- javascript - 合并两个对象数组,但在某个键/值上具有唯一性
- rust - Rust:我可以通过在更小的范围内以简单的方式借用整个固定大小的数组来获得固定大小的切片吗
- reactjs - 我应该在哪里为 Reactjs 中的 DOM 元素创建引用?
- c++ - c++ 11: &v[0] 在空的 std::vector v 上
- python - 如何使用比较矩阵的结果创建 DataFrame?
- java - 无法在操作栏上设置徽章