I'm trying to select all strings in my database that starts with a lowercase letter with regexp, but for some reason it's selecting all the strings that starts with a uppercase letter too. What am I doing wrong?
SELECT *
FROM `allData`
WHERE response REGEXP '^[a-z]'
LIMIT 0 , 30
Use the SQL LOWER() function if you want to convert a string column to lowercase. This function takes only one argument: the column whose values you want to lowercase. This function is a good choice if your database is case sensitive and you want to select only records matching a particular string.
From the MySQL REGEXP manual:
REGEXP is not case sensitive, except when used with binary strings.
You may therefore have some luck when using a binary string instead:
WHERE response REGEXP BINARY '^[a-z]'
Reasonably silly fiddle for demonstration: http://sqlfiddle.com/#!9/7eade/3
EDIT: As Ray says in the comments, you should probably use [[:lower:]]
instead in order to work across all collations, e.g.
WHERE response REGEXP BINARY '^[[:lower:]]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With