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!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...