I am trying to match strings with an addition of 1 at the end of it and my code gives me this problem:
- abcd01 should become abcde02 but my code gives me this output: abcde2
- foobar00 should become foobar01 but my code gives me this output: foobar1
- foobar001 should become foobar002
- foobar1 should become foobar2 My code:
def increment_string(strng):regex = re.compile(r'[0-9]')match = regex.findall(strng)nums = ''.join(match[-3:])strng = strng.replace(nums,'')add = int(nums)+1print(strng+str(add))