Splunk Search

Help with regex to remove first part of string?

tomapatan
Communicator

I have 2 fields: the values of fieldA are present in fieldB and I need to remove the first part of fieldB up to the values present in fieldA.

For example:

fieldA = BP498

fieldB = "A1John/Doe SmithBP498 XX XX XX"

Desired:

fieldB="BP498 XX XX XX"

Thanks in advance.

Labels (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@tomapatan 

Can you please try this?

YOUR_SEARCH
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

My Sample Search :

| makeresults 
| eval fieldA = "BP498",fieldB = "A1John/Doe SmithBP498 XX XX XX"
| rename comment as "upto this is sample data" 
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

Screenshot 2022-09-27 at 3.37.44 PM.png

I hope this will help you. 

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

 

View solution in original post

tomapatan
Communicator

worked for me, much appreciated.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@tomapatan 

Can you please try this?

YOUR_SEARCH
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

My Sample Search :

| makeresults 
| eval fieldA = "BP498",fieldB = "A1John/Doe SmithBP498 XX XX XX"
| rename comment as "upto this is sample data" 
| eval fieldB=fieldA+mvindex(split(fieldB,fieldA),1)

 

Screenshot 2022-09-27 at 3.37.44 PM.png

I hope this will help you. 

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

 

FelixLeh
Contributor

That's a cool way to remove something from a string! I'll add that to my repertoire, thanks!

0 Karma
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...