Splunk Search

How to write the regular expression to extract this field with rex?

sravankaripe
Communicator

Out of events, I have to pick extract <SERIAL_NUM>12456789</SERIAL_NUM> Please help me with the REX syntax in a search.

0 Karma
1 Solution

skoelpin
SplunkTrust
SplunkTrust

Your extracted field will be called SerialNumber

... | rex SERIAL_NUM\>(?<SerialNumber>\d+)

View solution in original post

0 Karma

sravankaripe
Communicator

rex (?\d+)

skoelpin
SplunkTrust
SplunkTrust

I downvoted this post because this won't work since you did not give the field a name..

also, why did you even post the question if you're going to post an incorrect answer and accept it? especially when more experienced splunkers provided you with answers that will work?

sravankaripe
Communicator

Ok, got it

0 Karma

sravankaripe
Communicator

rex < SERIAL_NUM >(?\d+)

0 Karma

gokadroid
Motivator

@skoelpin's answer should work great but just in case the serial number has non digits as well, please try this:

your query to reurn events
| rex "\<SERIAL_NUM\>(?<serial_num>[^\<]+)\<\/SERIAL_NUM\>"
| table serial_num
0 Karma

skoelpin
SplunkTrust
SplunkTrust

Your extracted field will be called SerialNumber

... | rex SERIAL_NUM\>(?<SerialNumber>\d+)

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...