Splunk Search

How to use regex on a field's value in a search?

splunkuser21
Engager
index=system* sourcetype=inventory  order=829

I am trying to extract the 3 digit field number in this search with rex to search all entries with only the three digit code. I tried:

index=system* sourcetype=inventory  (rex field=order "\d+")
index=system* sourcetype=inventory  (rex field=order "(\d+)")
index=system* sourcetype=inventory  (rex field=order "[0-9]{3}")

What is the correct way to do this?

Thanks!

0 Karma
1 Solution

MuS
SplunkTrust
SplunkTrust

Hi splunkuser21,

try this:

index=system* sourcetype=inventory  | rex field=order "(?<myOrder>\d{3})" | search myOrder=*

This will create a new field called myOrder which can be searched further down the search pipe.
Hope this helps ...

cheers, MuS

View solution in original post

skottska
New Member

You can also use

index=system* sourcetype=inventory | regex order="\d{3}"

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi splunkuser21,

try this:

index=system* sourcetype=inventory  | rex field=order "(?<myOrder>\d{3})" | search myOrder=*

This will create a new field called myOrder which can be searched further down the search pipe.
Hope this helps ...

cheers, MuS

MuS
SplunkTrust
SplunkTrust

You could also simply search for all orders below 1000 this will also return all order containing 3 digits:

index=system* sourcetype=inventory  order<1000
0 Karma

splunkuser21
Engager

Thanks @MuS !

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...