Reputation:
I'm trying to write a regular expression that matches if the string has a word, "worker", and doesn't have another, "TextNotification".
I have an example here with what I've been working: http://rubular.com/r/sjYWePWk0s
In this case, out of the four lines, I should only get matched the first one.
Upvotes: 1
Views: 50
Reputation: 15613
Do this as two separate tests.
worker
. If that test succeeds, thenTextNotification
. If that test fails, thenTrying to cram everything into one single regular expression is often
Upvotes: 0
Reputation: 785126
You are close. Use this regex with lookahead before actual match:
^(?!.*TextNotification).*worker.*$
Upvotes: 1