What's the easiest way to do a case-insensitive string replacement in Python?
The string type doesn't support this. You're probably best off using the regular expression sub method with the re.IGNORECASE option.
string
>>> import re >>> insensitive_hippo = re.compile(re.escape('hippo'), re.IGNORECASE) >>> insensitive_hippo.sub('giraffe', 'I want a hIPpo for my birthday') 'I want a giraffe for my birthday'
1.4m articles
1.4m replys
5 comments
57.0k users