Splunk Search

Regex to extract information in specific field

kirangurram
Explorer

Dear Experts ,
Need experts advice to extract "ABC6_IN_S14093456789" from below information which is available in field. I think Regex could be used to extract that filed. your help is appreciated.

 <Hdr Id="[ABC6_IN_S14093456789]-a411655e-069c-4ce5-b2d1-b0c22f54c4a3" Ver="0.001" Dtm="2019-05-02T15:59:55Z" TmOff="-07:00" />
Tags (1)
0 Karma
1 Solution

koshyk
Super Champion

Please try below . (The logic is to say greedily collect all characters until it finds ]

Id=\"\[(?P<my_id>[^\]]+)\]

Demo in Regex101

So in Splunk it would be (assuming _raw is your event)

 | rex "Id=\"\[(?<my_id>[^\]]+)\]"

View solution in original post

kirangurram
Explorer

thanks mate @koshyk. your answer served my purpose.

0 Karma

koshyk
Super Champion

Please try below . (The logic is to say greedily collect all characters until it finds ]

Id=\"\[(?P<my_id>[^\]]+)\]

Demo in Regex101

So in Splunk it would be (assuming _raw is your event)

 | rex "Id=\"\[(?<my_id>[^\]]+)\]"

lakromani
Builder

In Splunk P is not needed, so can write:

  | rex "Id=\"\[(?<my_id>[^\]]+)\]"

I think ] does not need to be escaped between [], so this should also work

  | rex "Id=\"\[(?<my_id>[^]]+)\]"
0 Karma

vnravikumar
Champion

Hi

Give a try

| makeresults 
| eval msg="<Hdr Id=\"[ABC6_IN_S14093456789]-a411655e-069c-4ce5-b2d1-b0c22f54c4a3\" Ver=\"0.001\" Dtm=\"2019-05-02T15:59:55Z\" TmOff=\"-07:00\" />" 
| rex field=msg "Id\=\"\[(?P<id>\w+)\]"
0 Karma

kirangurram
Explorer

thanks @vnravikumar . it works for some of the filed. it didnt work for the below sample.

from the below sample , I want to extract "android-2203920248ea8f16"

<Hdr Id="[android-2203920248ea8f16]-d451c5a7-e8e8-470a-93e8-f2c576c3507b" Ver="0.001" Dtm="2019-05-02T15:59:52Z" TmOff="-05:00" />
0 Karma

vnravikumar
Champion

Hi

Try this rex

Id\=\"\[(?P<id>)[\w-]+\]
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...