I have a regex which finds errors in a log for me:
/(exception|error)/i
This works, except that I do not want to be alerted when the following occurs, which I expect to happen:
DD/MM/YYYY 10:20pm: Read exception encountered
How do I specifically reject the 'Read exception encountered' string? I'm trying to use the ?! operator, but failing:
/(?!Read exception encountered)(exception|error)/i
The above still matches the string I want to exclude.
UPDATE: After experimenting with the negative lookbehind and lookahead solutions below, I have discovered that SiteScope supports only basic POSIX regex features, not extended features. Is a solution possible using only basic POSIX regex features?
You want to use "Negative Lookbehind" (if it's supported by your regex engine.) effectively you say "I want to match X patern, as long as this other pattern does NOT preceed it."
In your example, it looks like this:
/(?<!read )(exception|error)/i
see more about "lookaround" features here.
If you're looking to reject the entire string if the sub-string Read exception encountered
is in the string, then I would simply use a negative look ahead which is supported by most languages.
^(?![^\r\n]*?\bRead exception encountered\b)[^\r\n]*?(exception|error)
Live example: http://www.rubular.com/r/CV7P9huVsI
Try something like this /([^R][^e][^a][^d]) (exception|error)/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With