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!

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Community Feedback

We Want to Hear from You! Share Your Feedback on the Splunk Community   The Splunk Community is built for you ...

Manual Instrumentation with Splunk Observability Cloud: Implementing the ...

In our observability journey so far, we've built comprehensive instrumentation for our Worms in Space ...