Splunk Search

rex value up until 2 optional words

Cuyose
Builder

If I wanted to find the string "This is the error I want" in the following 2 events, what would the rex look like. I can't believe its not a common issue as I can not find a syntax in documentation anywhere that works

Message=This is the error I want. - ea1ff4f5-8c97-4ac4-9ba1-0f533a33f62b

Message=This is the error I want

Tags (2)
0 Karma

masonmorales
Influencer

Assuming there aren't any periods in the error you want, you could do:

rex "Message=(?<Yourfieldname>[^\.]+)"

If there are periods, you could do:

rex "Message=(?<Yourfieldnamehere>[^\s\-\s]+)\s\-\s"

Or

rex "Message=(?<Yourfieldnamehere>.+)\s\-\s"

You can also try out your own expressions at: http://www.regexr.com/

Cuyose
Builder

Hmm, I kinda figured this would be harder to explain. I needed to provide better examples. I edited the events. Basically it HAS to look for an end anchor that can be multiple strings.

Message=This is the. - error I want. - ea1ff4f5-8c97-4ac4-9ba1-0f533a33f62b

Message=This. - is the error I want

0 Karma

masonmorales
Influencer

Sorry, I'm not following. Perhaps you could explain another way? Also, please note that it is discourteous to down vote answers of people that are trying to help you.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...