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!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...