I have to replace text with text which was found. Smth like this:
regex = u'barbar'
oldstring = u'BarBaR barbarian BarbaRONt'
pattern = re.compile(regex, re.UNICODE | re.DOTALL | re.IGNORECASE)
newstring = pattern.sub(.....)
print(newstring) # And here is what I want to see
>>> u'TEXT1BarBaRTEXT2 TEXT1barbarTEXT2ian TEXT1BarbaRTEXT2ONt'
So I want to receive my original text, where each word that matches 'barbar' (with ignored case) will be surrounded by two words, TEXT1 and TEXT2. Return value must be a unicode string. How can I realize it? Thanks!