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!

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 ...