Splunk Search

How to return a url only to the 2nd slash?

isxtn
Explorer

So, this PCRE regex works in testers, but not on Splunk. 

 

^((http[s]?):\/)?\/?([^:\/\s]+)((\w+)*\/){2})

 

Should return https://someurl.com/first/

BUT in Splunk search, this:

 

rex field=referer "referer=(?<referer>^((http[s]?):\/)?\/?([^:\/\s]+)((\w+)*\/){2})

 

is returning the entire url, i.e., https://someurl.com/first/second/third/fourth/etc

What's the proper way to get what I'm looking for? Confused that this works in testers but not Splunk.

Labels (3)
Tags (1)
0 Karma
1 Solution

jotne
Builder

Just count 4 /

| makeresults 
| eval url="https://someurl.com/first/second/third/fourth/etc"
| rex field=url "(?<test>^(?:[^\/]*\/){4})"

View solution in original post

isxtn
Explorer

Thanks!

0 Karma

jotne
Builder

Just count 4 /

| makeresults 
| eval url="https://someurl.com/first/second/third/fourth/etc"
| rex field=url "(?<test>^(?:[^\/]*\/){4})"
Get Updates on the Splunk Community!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...