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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...