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.

Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...