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 Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...