Reputation: 675
I need a regex which matches
any_
But which does not match any of the strings below
any_group1
any_group2
I tried
(?=.*any_.*)^((?!any_group1).)*$^((?!any_group1).)*$
Upvotes: 1
Views: 151
Reputation: 163207
You might also use a negative lookahead (?!
to assert what is on the right is not group1 or group2:
\bany_(?!group[12]\b)
That will match:
\b
Word boundaryany_
Match literally(?!group[12]\b)
Negative lookahead to assert what is on the right is not group1 or group 2 followed by a word boundaryUpvotes: 1