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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...