Splunk Search

How to write the regex in my search to extract first part of uri path in access logs?

puneetkharband1
Path Finder

Below is the string I need to extract ROM_RAMESH from and similarly there are multiple client info so I need a regular expression and I am very new to that.
I used the extract field but can't get what I need ...

21.432.632.53 - - [14/Jan/2015:13:23:57 -0500] "GET /ROM_RAMESH/images/bg.gif HTTP/1.1" 200 64 - 38E8352722F7ADE88844A3B026752BCC.bgitcostumen1 - - https://cbsplake.boysdtom.com/ROM_RAMESH/BrandHistory.do -

When I use this:

 index="cc_web" sourcetype= * | rex field=_raw "(?i)^(?:[^\-]*\-){6}\s+(?P.+?)\w+\.\w+\s+" | top limit=100 Clients

I get only this as a result
https://cbsplake.boysdtom.com/ROM_RAMESH/

I need
ROM_RAMESH

Tags (2)
0 Karma

chanfoli
Builder

If your input is having the built-in httpd access transforms applied, you should have access to the uri_path field and this should work and give you a field called field1:

[your search]| rex field=uri_path "^/(?<field1>[^/]*)/"

If you are not using the access log transforms with this sourcetype then the following should also work for GET and POST requests:

 [your search] | rex field=_raw "(GET|POST)\s/(?<field1>[^/]*)/"
0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...