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!

Why You Can't Miss .conf25: Unleashing the Power of Agentic AI with Splunk & Cisco

The Defining Technology Movement of Our Lifetime The advent of agentic AI is arguably the defining technology ...

Deep Dive into Federated Analytics: Unlocking the Full Power of Your Security Data

In today’s complex digital landscape, security teams face increasing pressure to protect sprawling data across ...

Your summer travels continue with new course releases

Summer in the Northern hemisphere is in full swing, and is often a time to travel and explore. If your summer ...