Splunk Search

Can you help me come up with a regex expression which would extract a number from a string?

samwatson45
Path Finder

Hi,

I have a field which produces a value like this example: DB=HR_10_7_3043_TGTHRLIVE
I am trying extract the number and write it in the following way: DB_Version=10.7.3043
How do I get Splunk to cut off before and after the number and then replace the _ with .

Note: The strings before and after the numbers can vary in length, and the number can vary too.

Many thanks,
Sam

0 Karma
1 Solution

493669
Super Champion

Hi @samwatson45 ,
try this run anywhere search:

|makeresults|eval DB="HR_10_7_3043_TGTHRLIVE"|rex field=DB "^[A-Za-z]+_(?<DB_Version>\w+)_\w+"| eval DB_Version=replace(DB_Version,"_",".")

View solution in original post

0 Karma

493669
Super Champion

Hi @samwatson45 ,
try this run anywhere search:

|makeresults|eval DB="HR_10_7_3043_TGTHRLIVE"|rex field=DB "^[A-Za-z]+_(?<DB_Version>\w+)_\w+"| eval DB_Version=replace(DB_Version,"_",".")
0 Karma

samwatson45
Path Finder

Perfect thank you 🙂

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...