Case insensitive replacement?

Paul Rubin no.email at nospam.invalid
Tue Sep 27 13:28:28 EDT 2016


>  needle = "World"
>  haystack = "Hello, world!"
>  replacement = "THERE"
>  result = haystack.replace(needle, replacement, ignore_case=True)
>  # result would be "Hello, THERE!"

>>> import re
>>> re.sub('(?i)world','THERE','Hello World')
'Hello THERE'



More information about the Python-list mailing list