Splunk Search

How to extract data using rex ?

anil1219
Engager

Hi,

I want to extract value c611b43d-a574-4636-9116-ec45fe8090f8 from below.

Could you please let me know how I can do using rex field=httpURL

 

httpURL: /peerpayment/v1/payment/c611b43d-a574-4636-9116-ec45fe8090f8/performAction

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Or better, do not use regex because the URI has an inherent structure/convention that many APIs adhere to. (See, e.g., Re: How do I modify my rex command to remove direc...)  What you ask is the second to last segment of HTTP_PATH variable in CGI standard.

| eval actionID = mvindex(split(httpURL, "/"), -2)

Semantic code is easier to maintain and in this case, potentially cheaper than regex. 

Tags (2)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @anil1219,

if the structure of the URL is fixed, you could use 

| rex "\/\w+\/\w+\/\w+\/(?<your_field>[^\/]+)"

that you can test at https://regex101.com/r/K3yj0E/1

Cio.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...

Splunk AppDynamics Agents Webinar Series

Mark your calendars! On June 24th at 12PM PST, we’re going live with the second session of our Splunk ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2025 SplunkTrust is officially open! If you ...