Splunk Search

How to extract id from url message?

Span
Engager

Hi, I have below message and Iam trying to use rex to extract the id... But myid always shows empty.. Please help


- - [02/Nov/2022:17:43:03 -0400] "PUT /application/resources/cat/v7/product/1234567890003/status HTTP/1.1" 201 - abcd.com - 8 web-614

 

rex field=msg "/application/resources/cat/v7/product/(?<myid>[0-9]*)/status" | table myid

 

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

The sample data looks like _raw rather than msg.

You can try something like this which extracts any 13 digit number nested between forward slashes. This could be more flexible depending on the variability of your data. 

| rex "\/(?<myid>\d{13})\/"
| table myid

 

View solution in original post

johnhuang
Motivator

The sample data looks like _raw rather than msg.

You can try something like this which extracts any 13 digit number nested between forward slashes. This could be more flexible depending on the variability of your data. 

| rex "\/(?<myid>\d{13})\/"
| table myid

 

richgalloway
SplunkTrust
SplunkTrust

Slashes in regular expressions must be escaped.

rex field=msg "\/application\/resources\/cat\/v7\/product\/(?<myid>[0-9]*)/status" | table myid
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...