Splunk Search

How extract URI using regex?

karthi2809
Builder

I need to extract fields which mentioned in yellow?

alt text

0 Karma

esix_splunk
Splunk Employee
Splunk Employee

You can try the following...

(?<capture1>\/(\w+\/){3})\d+\/(?<capture2>\w+)\/.*\/(?<capture3>\w+)

In SPL...

| makeresults 
| eval URI="/v1/cp/members/257425525/benefits/999F-20180101-20181231-MED/excluded" 
| rex field=URI "(?<capture1>\/(\w+\/){3})\d+\/(?<capture2>\w+)\/.*\/(?<capture3>\w+)"

This will work for up to the third iteration. If you need to keep capturing, you can keep adding to that regex...

0 Karma

mayurr98
Super Champion

hey

you can try this run anywhere search

| makeresults | eval URI="/v1/cp/members/257425525/benefits/999F-20180101-20181231-MED/excluded" | rex field=URI "(?<first>^\/[^\/]+\/[^\/]+\/[^\/]+)\/[^\/]+\/(?<second>\w+)"

In your environment, you should write

 <base_search> | rex field=URI "(?<first>^\/[^\/]+\/[^\/]+\/[^\/]+)\/[^\/]+\/(?<second>\w+)"

let me know if this helps!

0 Karma

karthi2809
Builder

Hi mayurr

Thanks for you valuable answer but i send sample URI .there is lot of URI like this how can we extract using mode=sed

0 Karma

mayurr98
Super Champion

try this!
If you want to capture say benefits and excluded in one event then try this!

 | rex field=URI max_match=0 "(MED|\d{2,})\/(?P<sec>\w+)"

OR
if you want in three different field then use this

| rex field=URI "(?<first>^\/[^\/]+\/[^\/]+\/[^\/]+)\/[^\/]+\/(?<second>\w+)\/.*\/(?<Third>\w+)"
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...