Splunk Search

How to extract string after special character

eli_da
New Member

Hello everyone,

I have a simple question about rex, I have not been successful.

I have a string:

"bllablla_toni" 
"bloobloo_jony"

And I am want to extract the string after character "_".
The result will be:

"toni" 
"jony"

Thanks!

0 Karma

eli_da
New Member

,Is work

Thank!

0 Karma

vnravikumar
Champion

Hi @eli_da

Try this simple rex

| makeresults 
| eval str="bllablla_toni,bloobloo_jony" 
| makemv delim="," str 
| rex field=str "\_(?P<result>\w+)" 
| mvexpand result 
| table result

jaime_ramirez
Communicator

Hi

The following should do the trick:

[^_]+\_(?<extracted_string>.*)

Applied to rex (just copy and paste into splunk directly):

| makeresults 
| eval events="bllablla_toni bloobloo_jony"
| eval events=split(events, " ")
| mvexpand events
| rename events as strings
| rename COMMENT AS "--- Sample Generated Events Above ---"
| rex field=strings "[^\_]+\_(?<extracted_string>.*)"

Hope it helps

0 Karma
Get Updates on the Splunk Community!

Index This | What did the zero say to the eight?

June 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

Splunk Observability Cloud's AI Assistant in Action Series: Onboarding New Hires & ...

This is the fifth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Now Playing: Splunk Education Summer Learning Premieres

It’s premiere season, and Splunk Education is rolling out new releases you won’t want to miss. Whether you’re ...