Splunk Search

How to write the regex to extract the IP Address, but not CIDr notations from my sample data?

j666gak
Communicator

Hello,

I am trying to extract fields from a feed that I have, but the automated field extractor is not working for me though. I want to tag the IP address at the very end of every line and call it 'src_ip'. However the automated tool picks up the two CIDr notations every time as well as the IP address at the end of the line.

I am looking for Regex that will only pickup the IP address at the end of each line, and NOT the CIDr notations.

20150404 00:12 http://www.yahoo.com domain\user faddr=192.168.1.0/24 gaddr=192.168.1.0/24 192.168.1.68
20150404 00:12 http://www.yahoo.com domain\user faddr=192.168.1.0/24 gaddr=192.168.1.0/24 192.168.1.21

Would really appreciate somebody to provide me with the Regex it would be much appreciated.

Many thanks

0 Karma

rsennett_splunk
Splunk Employee
Splunk Employee

Here you go:

^([^\s]+\s+){6}(?P<src_ip>\d+\.\d+\.\d+\.\d+)
With Splunk... the answer is always "YES!". It just might require more regex than you're prepared for!
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...