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!

What’s New & Next in Splunk SOAR

Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us on ...

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...