我正在尝试解决一个问题,即在字符串的末尾添加1。
这意味着:
1. abcd12将变为:abcd13
2. abcd099将变为abcd100
3. abcd01将变为abcd02
4. ddh^add@2204将变为ddh^add@2205
我的代码:
import re
def increment_string(strng):
regex = re.compile(r'[0-9]')
match = regex.findall(strng)
nums = ''.join(match[-3:])
add = int(nums)+1
print(strng+str(add))
increment_string("abcd99")
代码输出结果为:abcd099100,我不知道如何解决。