Ranjith Ranjith - 1 year ago 86
Python Question

Matches whatever regular expression is not inside the parentheses

How can I match strings that are not inside a set of strings using python regular expressions?
Ex: set of strings ('/abc|/bcd')
I want to match any string other than that in the parentheses. That should be exact match.

Answer Source

Here's a fun one for you:


It uses a negative lookahead to ensure that the string being matched isn't one of the strings you don't want, then grabs whatever else is left.

Demo on Regex101

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download