문제

I want to retrieve all rows that have that have a certain column with only 2 words. I tried this, but it failed:

SELECT DISTINCT sentence FROM vocab WHERE p='adj' AND sentence REGEXP '^[a-zA-Z]+\s[a-zA-Z]+$'

This doesn't seem to work. Words can have ! or ? in it, so I don't think [a-zA-Z] is appropriate either way.

EDIT: I should rephrase it a bit, it should match any "group" of characters. Meaning

xczc zczxc~

1233 iojsd

´+a s~º

Could I use something like (.*) ?

도움이 되었습니까?

해결책

MySQL doesn't support \s so you can use [[:space:]] instead, you can try this:

SELECT DISTINCT sentence 
FROM vocab 
WHERE p='adj' 
AND sentence RLIKE '^[[:punct:][:alnum:]]+[[:space:]][[:punct:][:alnum:]]+$'

It'll look for rows where sentence is 2 words which may contain letters, ? or !

Sample SQLFiddle

다른 팁

Not very pretty but this should work

'^[a-zA-Z?!]+[[:space:]][a-zA-Z?!]+$'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top