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!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...