Quando ho cambiato due parole in una stringa con altre due parole usando re.sub ho ottenuto l'output. Ma quando ho provato che con uscita numeri non viene correttamenteSostituzioni multiple di numeri nella stringa usando regex python
>>> import re
>>> a='this is the string i want to change'
>>> re.sub('(.*)is(.*)want(.*)','\\1%s\\2%s\\3' %('was','wanted'),a)
'this was the string i wanted to change'
>>> re.sub('(.*)is(.*)want(.*)','\\1%s\\2%s\\3' %('was','12345'),a)
'this was\x8a345 to change'
>>>
non so il motivo per cui questo accade potrebbe u piacere tel me come usare questo Grazie in anticipo
Grazie mille. Sembra buona. – Myjab