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!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...