Splunk Search

Extract id from string using rex

rockts89
Engager

Hi all

How to extract id from String using rex?

sample:

sample-3456-777-text

result:

id
3456-777

Tags (2)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Try like

| makeresults 
| eval text="sample-3456-777-text" 
| rex field=text "-(?P<id>\d+\-\d+)-"

View solution in original post

renjith_nair
Legend

@rockts89 ,

Try

\w+-(?<id>[\d-]+)-\w+

Please provide more samples if you have other patterns

Happy Splunking!

vnravikumar
Champion

Hi

Try like

| makeresults 
| eval text="sample-3456-777-text" 
| rex field=text "-(?P<id>\d+\-\d+)-"
Get Updates on the Splunk Community!

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!

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

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...