Is MySQL the best way to get only CVCV values?

I have a database table with many words and rows. (Now it has over 300 thousand records, but it is growing.) What would be the best way to get only those values ​​that match the pattern? Let's say the table:

apples
oranges
abba
car
real
tipi
riot
tidy

Now, how to get only the CVCV template (ConsonantVowelConsonantVowel)? Or CVVC, LLLL (letter * 4), etc.? I could just create a column with different patterns:

word: real
patterns: LLLL,CVVC,LVVC,LVVL,LVLC,LLVC,LLLC,LVLL,CLLC,...

and search the database using "SELECT * FROM table WHERE word LIKE $ pattern", but I thought there is a better way?

+3
source share
2 answers

CVCV:

SELECT 'cara' REGEXP '[bcdfghjklmnpqrstvwxz][aeiouy][bcdfghjklmnpqrstvwxz][aeiouy]';

True

SELECT 'abba' REGEXP '[bcdfghjklmnpqrstvwxz][aeiouy][bcdfghjklmnpqrstvwxz][aeiouy]';

falsely

+2
source

4 , . , , , :

SELECT * 
FROM yourTable
WHERE yourField REGEXP '^[a-z]{4}$'

, a-z.

*** *** , , :

1) LOWER(yourField) REGEXP '^[a-z]{4}$'

OR

2) yourField REGEXP '^[a-zA-Z]{4}$'

- , , , . : http://dev.mysql.com/doc/refman/5.1/en/regexp.html

, .

-2
source

All Articles