Splunk Search

regex substr help

mcaulsc
Path Finder

Hi,

in anything else this would seem very simple but I seem to be flummoxed trying to do this in splunk. Probably not helped by having zero regex knowledge.

I have a field that has values in the format:  AAAABBCC

I want to return all values that have BB in position 5, if anyone could be so kind as to  provide a sample I can then pull it apart and try and work out how it does it.

Thanks.

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @mcaulsc,

ok, if you want to search the values "xx" in the fifth and sixth posizion, try something like this:

 

index=your_index
| eval BB=substr(your_field,5,2)
| search BB="xx"
| table _time your_field BB

 

 Ciao.

Giuseppe

View solution in original post

0 Karma

solarboyz1
Builder

Assuming characters 1-4=A 5-6=B and 7-8=C, the following should work:

| rex field=YourField "(?<A_values>....)(?<B_values>..)(?<C_values>..)

You should now have three fields A_values, B_values, and C_values.

 

gcusello
SplunkTrust
SplunkTrust

Hi @mcaulsc,

Please try something like this:

index=your_index
| eval BB=substr(your_field,5,2)
| table _time BB

or using a regex:

index=your_index
| rex field=your_field "\w{4}(?<BB>\w{2})\w{2"}
| table _time BB

Ciao.

Giuseppe

0 Karma

mcaulsc
Path Finder

thanks, that gets me a list of all the possible values in pos 5 for 2. What I want is the whole value if I have a match.

so if I have AAAABBCC I have a match on BB in pos5,2 so return AAAABBCC

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mcaulsc,

ok, if you want to search the values "xx" in the fifth and sixth posizion, try something like this:

 

index=your_index
| eval BB=substr(your_field,5,2)
| search BB="xx"
| table _time your_field BB

 

 Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mcaulsc,

good for you, see nect time!

Ciao and happy splunking.

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

mcaulsc
Path Finder

That's the one, been tying myself in knots with this for far longer than I should and ended up down regex rabbit holes that I didn't need to be down.
Many thanks for the 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!

Painting a Clearer Picture: Creating Cross-Domain Visibility with AI Canvas

    Thursday, June 25, 2026  |  11AM PDT / 2PM EDT  Duration: 1 Hour (Includes live Q&A) Register to ...

Analytics Workspace deprecation

As of Splunk Cloud Platform 10.4.2604 and Splunk Enterprise 10.4, Analytics Workspace is now deprecated. ...

Splunk Developer Day Recap: Building, Publishing, and Growing on the Splunk Platform

Splunk Developer Day brought the Splunk developer community together for a practical look at what it means to ...