Splunk Search

How to create a search to extract last word of the URL?

bsaujla131984
Path Finder

I need to create a search which extract last word of the URL as below:-

https://hostname/bs/cf/webservice/WordtoExtract ...

Please let me now how to extract last word of above URL i.e WordtoExtract.

Tags (1)

jpolvino
Builder

Lots of ways to solve this. Positive lookbehind is worth exploring!

 | makeresults 
 | eval url="https://hostname/bs/cf/webservice/WordtoExtract" 
 | rex field=url "(?<=\/)(?<theWord>\w+)$"

Regex101: https://regex101.com/r/eslxJR/1

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=url "\/(?<lastURLword>[^\/]+)$"
0 Karma

vnravikumar
Champion

Hi

Try this too

| makeresults 
| eval url="https://hostname/bs/cf/webservice/WordtoExtract" 
| eval temp=split(url,"/") 
| eval output = mvindex(temp,mvcount(temp)-1)
0 Karma

to4kawa
Ultra Champion
| makeresults 
| eval url="https://hostname/bs/cf/webservice/WordtoExtract" 
| eval output = mvindex(split(url,"/") ,-1)

That's enough.

0 Karma

renjith_nair
Legend

@bsaujla131984 ,

Try

|rex field=URL "\/(?<last_word>[^\/]*)$"
Happy Splunking!
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...