I would like to replace a string in form 'nnn0n' with the string in form 'nnn1n' where n is any digit. What the easiest way to do that? So, far I tried the following:
int(re.sub(r'^(\d+?)(0)(\d)$', r'\1???\3', '7001'))
But what ever I insert in place of '???' either just 1 or \1 returns incorrect result.
Any ideas?
EDIT:
I have come up with an ugly version:
re.sub(r'a1a', '1', re.sub(r'^(\d+?)(0)(\d)$', r'\1a1a\3', '7001'))
Anything nicer?
You can do something like:
Or if it’s not always three numbers before the 0 you want to replace:
Edit If you know that the number will always be of the same format, you can just use: