Splunk Search

Regex help in Splunk

Shashank_87
Explorer

Hi, I have few events in splunk like these -
1. "GET /test/materials/components/fields HTTP/1.1"
2. "GET /test1 HTTP/1.1" OR "GET /test2 HTTP/1.1
Now what i want is just to see the events which are like in the 2nd point. My query should ignore the 1st one's. The 2nd type of URL has a pattern that it has only one word after "/".

Can some one help?

Tags (2)
0 Karma
1 Solution

ragedsparrow
Contributor

You can not exclude with a regex pattern in your base search. You have to put it through the regex transformation to exclude events in the search via regex pattern matching. Example:

base search | regex url="\w+\s\/\w+\s.*"

That would only match the 2nd example shown

If you don't need the events at all, you may want to consider routing them to the nullQueue: https://docs.splunk.com/Documentation/Splunk/7.2.5/Forwarding/Routeandfilterdatad

The 2nd option will allow you to send specific events that you do not want to the nullQueue and they are not indexed. If you want it all to be indexed and then filtered at search time, you will need to use the regex specific transformation commands to filter them out.

View solution in original post

0 Karma

ragedsparrow
Contributor

You can not exclude with a regex pattern in your base search. You have to put it through the regex transformation to exclude events in the search via regex pattern matching. Example:

base search | regex url="\w+\s\/\w+\s.*"

That would only match the 2nd example shown

If you don't need the events at all, you may want to consider routing them to the nullQueue: https://docs.splunk.com/Documentation/Splunk/7.2.5/Forwarding/Routeandfilterdatad

The 2nd option will allow you to send specific events that you do not want to the nullQueue and they are not indexed. If you want it all to be indexed and then filtered at search time, you will need to use the regex specific transformation commands to filter them out.

0 Karma

somesoni2
Revered Legend

This is the full raw data OR full value of field??

your base search | regex _raw=".+\"\w+\s+\/\S+\s+\w+\/\d+\.\d+\".+"

OR if the extracted field name is URL

your base search | regex URL="\w+\s+\/\S+\s+\w+\/\d+\.\d+"
0 Karma

Shashank_87
Explorer

Hi Somesoni2, The above 2 points which i mentioned are 2 different events in my index. What i want is to fetch only 2nd type of events and exclude the 1st one's.
What will be the query look like?

0 Karma

somesoni2
Revered Legend

My solution is considering type 2 events. Try the same.

0 Karma

ehowardl3
Path Finder

As far the regex goes, the following will only match the examples in point 2:

\w+\s\/\w+\s.*

-E

0 Karma

Shashank_87
Explorer

Hi ehoward, Thank you for the response. Is there a way to exclude this in the search itself? I mean within the search query can we exclude all the URL's apart from the one's who follow pattern as 2nd point. This way we reduce the overhead and number of events

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...