Splunk Search

How to match start of field string using regex?

mhulse
Engager

Hello,

I am trying to match the start of a path in httpRequest.uri, as seen here:

index=xyz source=xyz 
| spath "httpRequest.headers{}.value"
| search "httpRequest.headers{}.value"="application/json"
| spath "httpRequest.uri"
| regex "^/public*"
| stats count by "httpRequest.uri"
| sort -count 

Unfortunately, it isn't working.

Can someone point out what I am doing wrong here?

If I get rid of the caret, the regex works, but it matches anywhere within the field’s string value. I need to start from the beginning of the string.

Thank you so much in advance!

 

Labels (1)
Tags (3)
0 Karma
1 Solution

scelikok
SplunkTrust
SplunkTrust

Hi @mhulse,

regex command works on _raw as a default. You need to tell the field like below;

index=xyz source=xyz 
| spath "httpRequest.headers{}.value"
| search "httpRequest.headers{}.value"="application/json"
| spath "httpRequest.uri"
| regex "httpRequest.uri"="^/public.*"
| stats count by "httpRequest.uri"
| sort -count 

 

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.

View solution in original post

scelikok
SplunkTrust
SplunkTrust

Hi @mhulse,

regex command works on _raw as a default. You need to tell the field like below;

index=xyz source=xyz 
| spath "httpRequest.headers{}.value"
| search "httpRequest.headers{}.value"="application/json"
| spath "httpRequest.uri"
| regex "httpRequest.uri"="^/public.*"
| stats count by "httpRequest.uri"
| sort -count 

 

 

If this reply helps you an upvote and "Accept as Solution" is appreciated.

mhulse
Engager

Thank you so much @scelikok!!! I greatly appreciate your help! 🙂

0 Karma
Get Updates on the Splunk Community!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...