making a MySQL regular expression case insensitive the hard way?

Skip Montanaro skip at mojam.com
Fri Sep 22 22:57:24 CEST 2000


I'm using MySQL from Python and occasionally have to use its regular
expression matching facilities.  Unfortunately, MySQL's REGEXP matching is
case-sensitive and there's no easy way to make it case insensitive, so I
have to do it the hard way, e.g. "abc" becomes "[aA][bB][cC]".

I've whipped up a simpleminded case desensitizer, but it makes no attempt to
completely parse the input regular expression.  For example, it doesn't
handle letters inside character sets because handling ranges would be more
effort than I want to expend on a Friday afternoon.

Has anyone got such a function that does this in a robust manner?  I think
it would be a nice little utility function to add to MySQLdb.py.

Skip




More information about the Python-list mailing list