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>[^\/]*)$"
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...