user132322
user132322

Reputation: 25

Regular Expression to search for string indicating error message but avoid specific string

I'd like to detect lines with error messages in a log file, but not one specific message.

Example:

bla ER2323 text<BR>
bla ER4444 text<BR>
bla Er2323333 text<BR>
bla bla bla
bla ER23 text<BR>
er1111 text<BR>

All error messages containing ER+4 digits should be captured, but NOT the ER4444 message.

Regular expression:

[Ee][Rr]+[0-9][0-9][0-9][0-9]

captures the error messages. How can I avoid the ER4444 message?

Upvotes: 0

Views: 85

Answers (1)

ipr101
ipr101

Reputation: 24236

You could use a negative lookahead -

[Ee][Rr](?!4444)\d{4}

Upvotes: 3

Related Questions