Splunk Search

REgex to extract fields

hashsplunk
Loves-to-Learn Lots

AZImaging/Projects/IMG2012002/WSI/D419BC00001/E7004004/SM/96b819b9-fc86-b81b-a999-55a72df0e05a.svs

Hi ,

Above is the string which i want to extract 2 fields . IMG2012002 and  D419BC00001. First value after 2 slashes and second value after 4 slashes . 

How can i write a regular expression for that ? Please help

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust
([^\/]+\/){2}(?<first>[^\/]+)\/[^\/]+\/(?<second>[^\/]+)

regex101.com is great for experimenting with regular expressions.

---
If this reply helps you, Karma would be appreciated.
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @hashsplunk,

please try this regex:

| rex "\w+\/\w+\/(?<field_1>\w+)\/\w+\/(?<field_2>\w+)"

that you can test at https://regex101.com/r/mJvW2M/1

if the string you shared is in a field, you could modify the rex in this way:

| rex field=your_field "^\w+\/\w+\/(?<field_1>\w+)\/\w+\/(?<field_2>\w+)"

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...