Splunk Search

Case statement with a regex?

klim
Path Finder

I'm trying to use a case statement and assign part of a field for each case statement. For example case(len(field)=5, regex that takes the first 3 characters of field, len(field=7), regex takes the first 5 characters,...)

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Are you always trying to get everything apart from the last two characters?

| eval part=substr(field,1,len(field)-2)

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Are you always trying to get everything apart from the last two characters?

| eval part=substr(field,1,len(field)-2)
0 Karma

klim
Path Finder

no that was just a coincidence but i think you provided the answer. Substr will do since each different length I want a substring of the field and it can be used in the case statement. Thanks

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...