cvp
Mar 28, 2020 - 09:52
I've a text 'Word word'
How can I replace the string 'word' independantly of its case by itself followed by a another string, exemple 'xxx'
Thus my text should become 'Wordxxx wordxxx'.
If I use
import re
my_text = 'Word word'
src_str = re.compile('word', re.IGNORECASE)
my_text = src_str.sub('wordxxx', my_text)
Result will be 'wordxxx wordxxx', thus I lose original case
I know I could loop on occurrences but if you know an easier way...