James
James

Reputation: 4052

Regex starts with, contains, and ends with

I'm trying to create a regular expression that is to be integrated in monitoring services. They are validated using golang regex.

So I was trying to create a regex that validates java exceptions. For example I have these exceptions (they are seperate lines)

java.lang.NoSuchMethodException: ...

java.lang.IllegalAccessException: ...

And I need a regular expressions that accepts exceptions only. Not errors, nor other types.

I'm able to catch java messages with this regular expression

pattern: "^java.lang"

But that also includes all types of errors, which is not intent. I was trying to make the regex to catch the word "exception" at the end, but I'm not sure how.

Upvotes: 0

Views: 3128

Answers (1)

The fourth bird
The fourth bird

Reputation: 163362

You could match any character zero or more times no greedy and then match Exception: .*?Exception: after ^java\.lang\. .

^java\.lang\..*?Exception:

Regex demo

Note to escape the dot to match it literally.

Upvotes: 5

Related Questions