Splunk Search

How do you retrieve date from the following string using regex?

ramesh12345
Explorer

Hi,

Test-20190212-0912 from this string. I want to retrieve date like this 2019-02-12

How do I write this in regex?
alt text

Tags (2)
0 Karma
1 Solution

vnravikumar
Champion

Hi @ramesh12345

Try this

| makeresults 
| eval str="Test-20190212-0912" 
| rex field=str "-(?P<year>\d{4})(?P<month>\d{2})(?P<date>\d{2})" 
| eval result= year."-".month."-".date

View solution in original post

0 Karma

tiagofbmm
Influencer

Use a rex first and to split the parts of it and then concatenate it to your new field

| makeresults | eval time="Test-20190212-0912" | rex field=time "Test-(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})"
| eval time=year+"-"+month+"-"+day
0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...