nurp
nurp

Reputation: 1275

Java regex to match pattern with exceptions

My Jenkins task searches the console output to see if the build is stable. It searches this java pattern: exception|error|warning|Segmentation

I have a compile parameter that has -Werror=format-security in it, so Jenkins should not match it. I try this [exception|error|warning|Segmentation][^Werror] but it still finds Werror in the text. How can I make it so it doesn't think my build is unstable because of compile parameter?

Upvotes: 0

Views: 1524

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626870

You may use

^(?!.*Werror).*(?:exception|error|warning|Segmentation)

See the RegexPlanet demo.

Details

  • ^ - start of string
  • (?!.*Werror) - there must not be a Werror substring anywhere on the line
  • .* - any 0+ chars other than line break chars as many as possible
  • (?:exception|error|warning|Segmentation) - one of the values inside the non-capturing alternation group.

Upvotes: 2

Related Questions