I wanted to match anything but a string using regex. I did some Googling and found this: ^(?:(?!test).)*
What do ?: and ?! do? Thanks.
(?:) is non-capturing. That means that a match occurs as usual, but the parentheses are only for grouping (in this case to attach a * operator to the entire thing); the matched value cannot be pulled out later with $1 or \1.
(?!) is a negative lookahead assertion. That means that it matches if the string in the parentheses does not exist there.
See http://docs.python.org/library/re.html for some more operators. While regex varies in different languages, they're fairly similar.
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