Ad
Code
Diff
  • import re
    def increment_string(s):
        if s=="": return "1"
        s = (s, s+"0")[s[-1].isalpha()]
        s, number = re.compile("(\D+)(\d+)").match(s).groups()
        return s+'{:0>{}}'.format(int(number)+1, len(number))
    • def increment_string(s,num='0'):
    • for i in range(len(s)-1,-1,-1):
    • if s[i].isalpha():
    • num = s[i+1:] if s[i+1:] else '0'
    • s = s[:i+1]
    • break
    • return s+'{:0>{}}'.format(int(num)+1,len(num))
    • import re
    • def increment_string(s):
    • if s=="": return "1"
    • s = (s, s+"0")[s[-1].isalpha()]
    • s, number = re.compile("(\D+)(\d+)").match(s).groups()
    • return s+'{:0>{}}'.format(int(number)+1, len(number))