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!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...