Splunk Search

How Do I Extract The End of String

IRHM73
Motivator

Hi, I wonder whether someone may be able to help me please.

From a field called 'detail.input' there are two potential outputs as shown below:

Request to /for/submissions/1234567890 and Request to /for/savedforlater/9876543210

What I'd like to do is extract the number at the end of the string.

I'd thought about using a regex, but because of the difference in the string, i.e. "submissions" as opposed to "savedforlater", I wasn't sure whether this could be done, so I wondered if I could the 'str' and 'len' commands.

I know how to omit the end of the character string, but I was wondering whether someone may be able to provide some guidance please how I can extract the end of the character string.

Many thanks and kind regards

Chris

0 Karma
1 Solution

javiergn
Super Champion

Something like this should do the trick (not tested):

rex "\/(?<mynumber>\d+)$"

If the number is not the last part of your string then I can provide something different.

View solution in original post

javiergn
Super Champion

Something like this should do the trick (not tested):

rex "\/(?<mynumber>\d+)$"

If the number is not the last part of your string then I can provide something different.

IRHM73
Motivator

Hi @javiergn, thank you for taking the time to reply to my post.

The solution works great, but so that I can improve my understanding, could you perhaps explain what the rex is doing?

Many thanks and kind regards

Chris

0 Karma

ziegfried
Influencer

Check out the explanation here: https://regex101.com/r/eY4cN2/1 (tab on the right hand side)

IRHM73
Motivator

Ah, thanks for that @ziegfried.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...