Splunk Search

Field extraction regex breaks due to date change and space

ershad_c
Engager

The date field sometimes has 2 spaces and sometimes 1 space, depending on whether the date is a single digit or double digit. eg. 

May[space][space]9

vs 

May[space]10

as a result the field extraction regex finds the wrong field in the first 10 days of the month. 

sample regex that splunk comes up with  - ^(?:[^ \n]* ){9}(?P<ResponseTime>\d+)

I would have expected this to be a common enough problem but I can't seem to google the answer 😞

TIA for your assistance for this regex Newbie

 

 

Labels (2)
0 Karma

renjith_nair
Legend

Adding a '+' to your white space should fix the issue

Please find a run anywhere example and test if it works for you. If not, please provide a sample event you are trying to extract

|makeresults |eval date="May  1 2021,May  2 2021,May  3 2021,May 10 2021,May 11 2021"|makemv date delim=","| mvexpand date
|rex field=date "\w+\s+(?<Day>\d+)"
---
What goes around comes around. If it helps, hit it with Karma 🙂

ershad_c
Engager

Thanks! was able to combine your solution with my data on regex101 and figure it out.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...