I wanted to match anything but a string using regex. I did some Googling and found this: ^(?:(?!test).)*
What do ?: and ?! do? Thanks.
I wanted to match anything but a string using regex. I did some Googling
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(?:) 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.