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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...