Splunk Search

Rex to select number from string

abbam
Explorer

Hi All,

I am trying to select numbers from a field using Rex, but I cannot seem to figure it out.

Basically the values that i have in the field are:

XX (432)
FH02 (2356)
YR01 (855553)

I want to be able to select the number in the () - this number can be of any length.

How can I do this?

Thanks!

0 Karma
1 Solution

mayurr98
Super Champion

You can try something like this

<your base search> | rex field=<fieldname> "\s\((?<number>[^\)]+)"

let me know if this helps!

View solution in original post

0 Karma

mayurr98
Super Champion

You can try something like this

<your base search> | rex field=<fieldname> "\s\((?<number>[^\)]+)"

let me know if this helps!

0 Karma

mayurr98
Super Champion

try this if the field is multivalue

| rex field=<fieldname> max_match=0 "\s\((?<number>[^\)]+)"
0 Karma

abbam
Explorer

thank you! worked perfectly!

0 Karma

493669
Super Champion

Hi @abbam,
try this:

|rex field=<fieldname> "\((?<number>\d+)"

try this run anywhere search:

|makeresults|eval sample="XX (432)"|rex field=sample "\((?<number>\d+)"
0 Karma

abbam
Explorer

Thank you!

How would you do it if the field was multivalue?

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...