Ad
Code
Diff
  • import re
    
    def increment_string(s):
        end_nums = re.match(".+?(\d+)$", s)
        
        if end_nums:
            padded_number = '{:0>{}}'.format(int(end_nums[1])+1, len(end_nums[1]))
            return s[:end_nums.span(1)[0]] + padded_number
        return s + '1'
    • 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))
    • end_nums = re.match(".+?(\d+)$", s)
    • if end_nums:
    • padded_number = '{:0>{}}'.format(int(end_nums[1])+1, len(end_nums[1]))
    • return s[:end_nums.span(1)[0]] + padded_number
    • return s + '1'