I want to replace characters at the end of a python string. I have this string:
s = \"123123\"
I want to replace the last 2 with
2
When the wanted match is at the end of string, re.sub comes to the rescue.
>>> import re >>> s = "aaa bbb aaa bbb" >>> s 'aaa bbb aaa bbb' >>> re.sub('bbb$', 'xxx', s) 'aaa bbb aaa xxx' >>>