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
import re s = "123123" s = re.sub('23$', 'penguins', s) print s
Prints:
1231penguins
or
import re s = "123123" s = re.sub('^12', 'penguins', s) print s
penguins3123