I’d like to test whether a string contains "Kansas" followed by anything other than " State".
Examples:
"I am from Kansas" true
"Kansas State is great" false
"Kansas is a state" true
"Kansas Kansas State" true
"Kansas State vs Kansas" true
"I'm from Kansas State" false
"KansasState" true
For PCRE, I believe the answer is this:
'Kansas(?! State)'
But Mysql’s REGEXP doesn’t seem to like that.
ADDENDUM: Thanks to David M for generalizing this question:
How to convert a PCRE to a POSIX RE?
More efficient than that large regex (depending, of course, on your data and the quality of the engine) is
If Kansas usually appears in the form ‘Kansas State’, though, you may find this better:
This has the added advantage of being easier to maintain. It works less well if Kansas is common and text fields are large. Of course you can test these on your own data and tell us how they compare.