Splunk Search

How to exclude a match in regex - Regex

Kanesol
Explorer

I have this search:

index="blah" source="blah" cs_Referer_="-" NOT(some keyword exclusion here) | regex cs_host="^(\b\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\b)+"

and I wish to add this to it as a NOT :

regex cs_uri_stem="\?d=[\w.]+@\w+.\w+"

Not sure how to go about this. Any Input is appreciated.

Tags (1)
1 Solution

hexx
Splunk Employee
Splunk Employee

I think you've got the most reasonable solution already with this search:

index="blah" source="blah" cs_Referer_="-" NOT(some keyword exclusion here) | regex cs_host="^(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)+" | regex cs_uri_stem="\?d=[\w.]+@\w+.\w+"

Attempting to contract both regular expressions into one probably won't yield any performance benefits.

View solution in original post

hexx
Splunk Employee
Splunk Employee

I think you've got the most reasonable solution already with this search:

index="blah" source="blah" cs_Referer_="-" NOT(some keyword exclusion here) | regex cs_host="^(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)+" | regex cs_uri_stem="\?d=[\w.]+@\w+.\w+"

Attempting to contract both regular expressions into one probably won't yield any performance benefits.

Kanesol
Explorer

Thanks for confirming that for me. I was hoping for something a little nicer.

0 Karma

Kanesol
Explorer

To update, I've resorted to just adding more and more pipes for each regex which I believe is not optimal but serviceable. I'm hoping someone can come up with a more elegant way 🙂

index="blah" source="blah" cs_Referer_="-" NOT(some keyword exclusion here) | regex cs_host="^(bd{1,3}.d{1,3}.d{1,3}.d{1,3}b)+" | regex cs_uri_stem!="?d=[w.]+@w+.w+"

Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...