REGEXP - select only lines containing letters and full stop

I am trying to write this query, I need to select rows where the column has only letters (az) and a full stop.

I tried this, but it did not work:

SELECT * FROM table WHERE (c1 REGEXP '[^a-zA-Z\.]') = 0 

This one usually works in PHP.

+4
source share
1 answer

Try:

 SELECT * FROM table WHERE c1 REGEXP '^[a-zA-Z.]+$' 

Anchor ^ and $ guarantees the correspondence of the whole line, and not its part. Then the character class [a-zA-Z.] Corresponds to one upper or lower case letter or period. + is a quantifier for one or more repetitions of the previous sub-mode, so in this case it allows us to match one or more periods or upper / lower case letters.

Additional Information on Using Regular Expressions in MySQL

+7
source

Source: https://habr.com/ru/post/1434367/


All Articles