Splunk Search

Regex for CIDR exclusion

aknsun
Path Finder

Hi,

Need some help with getting a correct Regex for CIDR exclusion.

*(This is an example. Not the real IP range. )

Trying to exclude events that have ips in the 79.40.96.0/22 range.

Following is the Regex that I was able to create using https://regex101.com/. It does match when I test with IPs from the range, in https://regex101.com. However it doesn't seem to work when I test it against events in Splunk.

And the regex used is:

^79\.40\.(96\.([1-9]|[1-9]\d|[12]\d\d)|99\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-4])|9[78]\.([1-9]?\d|[12]\d\d))$

(Looked like it didn't get pasted correctly when I posted initially.)

Sample event would start with the ip.

79.40.96.12 .......

Thanks,

AKN

0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval ip=split("79.40.96.#79.40.97.#79.40.98.#79.40.99.","#")
| stats count by ip
| eval subnet=mvrange(0,255)
| stats values(ip) as ip by subnet
| mvexpand ip
| eval ip=ip.subnet
| eval check=if(match(ip,"79\.40\.9[6-9]\.[1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]"),"OK","false")

79.40.96.0/22 is the range 79.40.96.0 ~ 79.40.99.255
the regex is match() args.

0 Karma

techiesid
SplunkTrust
SplunkTrust

@aknsun ,

Can you please remove the $ from the end of your regex and try. your regex should looks like below,

^79\.40\.(96\.([1-9]|[1-9]\d|[12]\d\d)|99\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-4])|9[78]\.([1-9]?\d|[12]\d\d))

Sid

0 Karma

aknsun
Path Finder

Hi @techiesid . It didn't work.

Sample event has a comma immediatley after the IP.

79.40.96.12, ........

0 Karma

aknsun
Path Finder

I got this working. Just had to replace the "$" with a ".*" at the end of the REGEX.

^79\.40\.(96\.([1-9]|[1-9]\d|[12]\d\d)|99\.([1-9]?\d|1\d\d|2[0-4]\d|25[0-4])|9[78]\.([1-9]?\d|[12]\d\d)).*
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@aknsun

Have you tried cidrmatch function for exclusion ?

   ... |where NOT cidrmatch("79.40.96.0/22",ipfield)  
0 Karma

aknsun
Path Finder

Hi @kamlesh_vaghela I'm trying to get this done in props/transforms as I don't want it ingested into Splunk.

Thanks,

AKN

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@aknsun
Can you please share some sample 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!

Data Management Digest – August 2026

MichelleCorpora_1-1788182384472.png Welcome to the August 2026 edition of Data Management Digest! August was a ...

Your Feedback. Our Roadmap. Visit the PX Feedback Booth at .conf26

You use Splunk every day, come and help shape what's next.  Save Your Seat: Product-Focused Sessions at ...

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...