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!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...