Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitivity in Python strings

Tags:

python

I know that you can use the ctypes library to perform case insensitive comparisons on strings, however I would like to perform case insensitive replacement too. Currently the only way I know to do this is with Regex's and it seems a little poor to do so via that.

Is there a case insensitive version of replace()?

like image 718
Teifion Avatar asked Dec 06 '22 06:12

Teifion


1 Answers

You can supply the flag re.IGNORECASE to functions in the re module as described in the docs.

matcher = re.compile(myExpression, re.IGNORECASE)
like image 53
zdan Avatar answered Dec 10 '22 10:12

zdan