0

Similar subjects have been discussed many time, but up to now, I've not found the right syntax, if it possible, corresponding to my need.

I want to raise alerts depending on a particular substring in a logfile but avoiding to have alerts when a another substring (to ignore) is present on the same line.

Substrings are always in the same order on the line when both are present with other strings before, between and after like this:

bla bla bla StringToIgnore bla bla bla StringToLookFor bla bla bla

To summarize, with a logical syntax, I would like to do: StringToLookFor AND (NOT StringToIgnore)

I must use for this a unique regular expression. The regular expression is entered though a field on the tool generating the logs. No other combination, logic, code or script is possible.

2
  • Please provide real examples. Commented Jan 8, 2015 at 14:24
  • Regular expressions are really not the best tool for this sort of thing. Commented Jan 8, 2015 at 14:42

1 Answer 1

1

I think this does what you want:

^(?=.*StringToLookFor)(?!.*StringToIgnore).*

with multi-line modifier m.

regex101 demo.

The .* bit at the end is only to make the match easier to see, it's not actually required.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.