Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding small letter between two capital letters - MySQL

Tags:

select

mysql

I've got problem - I need to find every single phrase like AbC (small b, between two Capital letters). For Example a statement: Little John had a ProBlEm and need to know how to do tHiS.

I need to select ProBlEm and tHiS (you see, BlE and HiS, one small letter in between two capital). How can I select this?

like image 987
Paweł Adamczyk Avatar asked Nov 13 '22 01:11

Paweł Adamczyk


1 Answers

In MySQL you can use a binary (to ensure case sensitivity) regular expression to filter for those records that contain such a pattern:

WHERE my_column REGEXP BINARY '[[:upper:]][[:lower:]][[:upper:]]'

However, it is not so straightforward to extract the substrings which match such a pattern from within MySQL. One can use a UDF, e.g. lib_mysqludf_preg, but it's probably a task more suited to being performed within your application layer. In either case, regular expressions can again help to simplify this task.

like image 67
eggyal Avatar answered Nov 15 '22 05:11

eggyal