Random RLIKE

Consider the datatbl table as follows:

 +----------+ | strfield | +----------+ | abcde | | fgHIJ | | KLmno | +----------+ 

I want to write a query something like this:

 select * from datatbl where strfield rlike '[az]*'; 

As in a non-SQL regex, I would like to return a w / abcde , but not a w / capitals string. I can't seem to find an easy way to do this. Am I missing something stupid?

Thanks Joe

+7
regex mysql
source share
1 answer

MySQL REGEXP / RLIKE sucks for this - you need to treat the data as BINARY for case sensitive searches:

 SELECT * FROM datatbl WHERE CAST(strfield AS BINARY) rlike '[az]*'; 

You will find this in the comments for the REGEXP / RLIKE documentation .

+13
source share

All Articles