Splunk Search

How can I improve my regular expression to extract a field located inside a URL?

guillecasco
Path Finder

Hey i have the following logs:

INCOMING REQUEST:
URL:  /pop/v1/enviro/2ee999b4-d97ba81bdefd/updatesearching/

i need to extract the numbers after enviro/ and before /updatesearching

i created following regular expression: REX "URL:\s\/\w+\/\w+\/\enviro/(?.*)/updatesearching/

but i'm not getting it. how can i improve the regular expression or how can i extract that number?

0 Karma
1 Solution

gokadroid
Motivator

Can you please try this and see if it works for you:

If it's always between enviro and updatesearching:

your query to return events
|rex field=_raw "enviro\/(?<capturedNum>[^\/]+)\/updatesearching"
| table capturedNum

If the numbers of interest come always after enviro:

your query to return events
|rex field=_raw "\/enviro\/(?<capturedNum>[^\/]+)\/"
| table capturedNum

If it's always the fourth element then try this:

your query to return events
|rex field=_raw "URL:\s*\/([^\s\/]+\/){3}(?<capturedNum>[^\/]+)\/"
| table capturedNum

View solution in original post

gokadroid
Motivator

Can you please try this and see if it works for you:

If it's always between enviro and updatesearching:

your query to return events
|rex field=_raw "enviro\/(?<capturedNum>[^\/]+)\/updatesearching"
| table capturedNum

If the numbers of interest come always after enviro:

your query to return events
|rex field=_raw "\/enviro\/(?<capturedNum>[^\/]+)\/"
| table capturedNum

If it's always the fourth element then try this:

your query to return events
|rex field=_raw "URL:\s*\/([^\s\/]+\/){3}(?<capturedNum>[^\/]+)\/"
| table capturedNum

guillecasco
Path Finder

it worked! |rex field=_raw "enviro\/(?[^\/]+)\/updatesearching" thanks dude

0 Karma

guillecasco
Path Finder

what is the field=_raw does exactly. I didnt put there anything

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...