Splunk Search

How to match a regex field using wildcard

adj24
Engager

Hi, I have the following search:

search
| spath input=rawJsonData output=UserActionAttributes path=UserActionAttributes
| rex max_match=0 field=UserActionAttributes "pn:(?<partNumber>\d{4,5}[a-zA-Z]\d{1,3})"
| rex max_match=0 field=UserActionAttributes "compNm:((?<compName>(.*?))\")"
| eval zip = mvzip(partNumber,compName)
| mvexpand zip
| eval zip= split(zip,",")
| eval partNumber=mvindex(zip,0)
| eval compName=mvindex(zip,1)
| dedup bid, partNumber,compName

| eval compcheck = if(like(partNumber,"%".compName."%"),"Contained","Not Contained")
| table partNumber,compName, compcheck

 

The returned values could look like this (compName is not uniform, it could really be anything. Sometimes doesn't contain part number at all, which is what I'm looking for)

partNumber: 333T4343

compName: blahblah_333T4343_blah


I want the compcheck to tell me that compName contains partNumber in this case, but it's not working. I've also tried (also does not work):

| eval compcheck = if(match(partNumber,compName),"Contained","Not Contained")

Please help 🙂 

Labels (6)
Tags (3)
1 Solution

The_Simko
SplunkTrust
SplunkTrust

Well, I spent too much time trying something before figuring out to flip your variables.  

Try like this:
| makeresults
| eval partNumber = "333T4343"
| eval compName = "blahblah_333T4343_blah"
| eval AreTheseTheSame = if(match(compName,partNumber),"Contained","Not Contained")

View solution in original post

adj24
Engager

@The_Simko  omg....how did I not realize that. Thank you so much!!! 

The_Simko
SplunkTrust
SplunkTrust

Well, I spent too much time trying something before figuring out to flip your variables.  

Try like this:
| makeresults
| eval partNumber = "333T4343"
| eval compName = "blahblah_333T4343_blah"
| eval AreTheseTheSame = if(match(compName,partNumber),"Contained","Not Contained")

Get Updates on the Splunk Community!

Devesh Logendran, Splunk, and the Singapore Cyber Conquest

At this year’s Splunk University, I had the privilege of chatting with Devesh Logendran, one of the winners in ...

There's No Place Like Chrome and the Splunk Platform

WATCH NOW!Malware. Risky Extensions. Data Exfiltration. End-users are increasingly reliant on browsers to ...

Customer Experience | Join the Customer Advisory Board!

Are you ready to take your Splunk journey to the next level? &#x1f680; We invite you to join our elite squad ...