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!

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

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...