How can I match a string that is NOT partners?
Here is what I have that matches partners:
/^partners$/i
I’ve tried the following to NOT match partners but doesn’t seem to work:
/^(?!partners)$/i
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.
Your regex
only matches empty lines because you didn’t include the end-of-line anchor in your lookahead assertion. Lookaheads do just that – they “look ahead” without actually matching any characters, so only lines that match the regex
^$will succeed.This would work:
This reports a match with any string (or, since we’re in Ruby here, any line in a multi-line string) that’s different from
partners. Note that it only matches the empty string at the start of the line. Which is enough for validation purposes, but the match result will be""(instead ofnilwhich you’d get if the match failed entirely).