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!

Splunk App for Anomaly Detection End of Life Announcment

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...