Я думаю, вы можете использовать finditer
, чтобы найти все позиции совпадений в тексте.Затем замените их один за другим.
import re
text = '''This is a dummy text. I want the `.` of 12.12 to go away.
I want to replace it with a `,`. Lets see if it works.'''
p = re.compile(r"\d\.\d")
for m in p.finditer(text):
text = text[:m.start() + 1] + ',' + text[m.start() + 2:]
print(text)
Вывод будет
This is a duppy text. I want the `.` of 12,12 to go away.
I want to replace it with a `,`. Lets see if it works.