Mike
Mike

Reputation: 1738

Regex For Log Parsing

I am trying to find all of the exceptions that are in a log that are not of type InvalidArgumentException. Our log writes out lines like the following:

Class:       InvalidArgumentException

The regex I am trying to use is:

/Class:.*(!InvalidArgument)Exception/

Essentially, start with the word Class:, allow any characters after class that are not equal to InvalidArgument, and then include the word Exception

Thank you for your help.

Upvotes: 1

Views: 155

Answers (1)

Kent
Kent

Reputation: 195229

one possibility with negative look behind:

/^Class:.*?(?<!InvalidArgument)Exception/

test with grep -P:

kent$  echo "Class:   foo    InvalidArgumentException
Class: bar NullPointerException"|grep -P '^Class:.*?(?<!InvalidArgument)Exception'
Class: bar NullPointerException

Upvotes: 2

Related Questions