Hi
I have table with rows of strings. I'd like to search for those strings that consists of only two words.
I tried few ways with [[:space:]] etc but mysql was returning three, four word strings also
Hi
I have table with rows of strings. I'd like to search for those strings that consists of only two words.
I tried few ways with [[:space:]] etc but mysql was returning three, four word strings also
^\w+\s\w+$
should do well.
Note; what I experience more often in the last days is that close to nobody uses the ^$
-operators.
They are absolutely needed if you want to tell if a string starts or ends with something or want to match the string exactly, word for word, as you. "Normal" strings, like you used (I assume you used something like \w[:space]\w
match in the string, what means that they also match if the condition is true anywhere within the string!
Keep that in mind and Regex will serve you well :)
try this:
select * from yourTable WHERE field REGEXP('^[[:alnum:]]+[[:blank:]]+[[:alnum:]]+$');
more details in link : http://dev.mysql.com/doc/refman/5.1/en/regexp.html