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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...