I need to make sure a given string is not "Select a value". That's it, anything else should match the pattern, except this exact string.
I've been looking around and trying many combinations on http://www.regular-expressions.info/javascriptexample.html but nothing seems to do the trick.
I can't negate the test, the pattern needs to do it all since I'll feed this to a form validation framework. If the select contains this text, I'll return an error, etc. So the pattern must match anything else, except this exact string,
I tried lots of things,
(?!Select an account)
!(Select an account)
!(^(Select an account)$)
etc... clearly I don't understand how some of these mechanisms work. I get the "starts with" and 'ends with", but I don't seem to find a simple negation operator.
For some reason everywhere I look for regex explanations I don't get this simple use case, maybe it's not common.
How can I accomplish this?
Thank you!
I believe this was asking something similar:
Regular Expressions and negating a whole character group
In your case you could use something like
^(?!Select a value).*$
Which would match everything that does NOT start with "Select a value."
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