Your job is to write a function which increments a string, to create a new string.

- If the string already ends with a number, the number should be incremented by 1.
- If the string does not end with a number. the number 1 should be appended to the new string.

Examples:

`foo -> foo1`

`foobar23 -> foobar24`

`foo0042 -> foo0043`

`foo9 -> foo10`

`foo099 -> foo100`

*Attention: If the number has leading zeros the amount of digits should be considered.*

Difficulty: introductory

Starter code:

def increment_string(strng):
	

Solutions:
def increment_string(strng):
    head = strng.rstrip('0123456789')
    tail = strng[len(head):]
    if tail == "": return strng+"1"
    return head + str(int(tail) + 1).zfill(len(tail))

def increment_string(strng):
    
    # strip the decimals from the right
    stripped = strng.rstrip('1234567890')
    
    # get the part of strng that was stripped
    ints = strng[len(stripped):]
    
    if len(ints) == 0:
        return strng + '1'
    else:
        # find the length of ints
        length = len(ints)
    
        # add 1 to ints
        new_ints = 1 + int(ints)
    
        # pad new_ints with zeroes on the left
        new_ints = str(new_ints).zfill(length)
    
        return stripped + new_ints

import re

def increment_string(input):
    match = re.search("(\d*)$", input)
    if match:
        number = match.group(0)
        if number is not "":
            return input[:-len(number)] + str(int(number) + 1).zfill(len(number))
    return input + "1"


def increment_string(s):
    if s and s[-1].isdigit():
        return increment_string(s[:-1]) + "0" if s[-1] == "9" else s[:-1] + repr(int(s[-1]) + 1)
    return s + "1"


import re
def increment_string(strng):
    m = re.match('^(.*?)(\d+)$', strng)
    name, num = (m.group(1), m.group(2)) if m else (strng, '0')
    return '{0}{1:0{2}}'.format(name, int(num)+1, len(num))

def increment_string(s):
    if s and s[-1].isdigit():
        num = s[len(s.rstrip("0123456789")):]
        return s[:-len(num)] + str(int(num) + 1).zfill(len(num))
    
    return s + "1"

def increment_string(strng):
    text = strng.rstrip('0123456789')
    nums = strng[len(text):]
    if nums == "": return strng+"1"
    return text + str(int(nums) + 1).zfill(len(nums))

def increment_string(s):
    c = s.rstrip('0123456789')
    n = s[len(c):]
    if n=='':
        return s+'1'
    else:
        return c+str(int(n)+1).zfill(len(n))

increment_string=f=lambda s:s and s[-1].isdigit()and(f(s[:-1])+"0",s[:-1]+str(int(s[-1])+1))[s[-1]<"9"]or s+"1"

import re

def increment_string(s):
    number = re.findall(r'\d+', s)
    if number:
        s_number = number[-1]
        s = s.rsplit(s_number, 1)[0]
        number = str(int(s_number) + 1)
        return s + '0' * (len(s_number) - len(number)) + number
    return s + '1'

def increment_string(s):
    from re import findall as fa
    return (s.replace((fa('(\d+)', s))[-1], str(int((fa('(\d+)', s))[-1])+1).rjust(len((fa('(\d+)', s))[-1]),'0')) if (fa('(\d+)', s)) else s + '1')

import re
def increment_string(strng):
    if not strng or not strng[-1].isdigit(): return strng + '1'
    num = re.match('.*?([0-9]+)$', strng).group(1)
    return strng[:-len(num)] + str(int(num)+1).zfill(len(num))

import string


def increment_string(strng):
    if strng == '':
        return '1'
    a = list(strng)
    s = ''
    for i in range(0, len(a)):
        if a[-1] in string.digits:
            s += a[-1]
            del a[-1]
    s = reversed(s)
    s = ''.join(s)
    if s == '':
        s = '0'
    c = len(s)
    aa = int(s)
    aa += 1
    a = ''.join(a)
    return str(a) + str(aa).zfill(c)

import re
def increment_string(strng):
    res = re.search(r"^(.*?)(\d*)$",strng)
    ln = len(res.group(2))
    idx = int(res.group(2)) if ln else 0
    return res.group(1)+str(idx+1).zfill(ln)


def increment_string(s):
    import re
    if s and s[-1].isdigit():
        num = re.search(r'(\d+)$', s).group(1)
        return re.sub(num, str(int(num) + 1).zfill(len(num)), s)
    return ''.join([s, '1'])

def increment_string(s):
    if s and s[-1].isdigit():
        n = s[len(s.rstrip('0123456789')):]
        return s[:len(s) - len(n)] + '%0*d' % (len(n), int(n) + 1)
    
    return s + '1'

def increment_string(s):
    if s == '' or not s[-1].isdigit(): return s + '1'
    
    n = s[len(s.rstrip('0123456789')):]
    return s[:len(s) - len(n)] + '%0*d' % (len(n), int(n) + 1)


import re

def increment_string(s):
    n = ''.join(re.findall(r'\d*$', s))
    l = len(s) - len(n)
    n = '0' if n == '' else n
    
    return s[:l] + '%0*d' % (len(n), int(n) + 1)

def increment_string(strng):
    s1 = strng.rstrip('0123456789')
    s2 = strng[len(s1):]
    if s2 == '': return strng+'1'
    return s1 + str(int(s2)+1).zfill(len(s2))

def increment_string(strng):
    import re
    match = re.search(r'\d+$', strng)
    if match:
        s = match.group()
        s1 = strng[:len(strng)-len(s)] + str.rjust(str(int(s)+1), len(s), '0')
    else:
        s1 = strng+'1'
    return s1

def increment_string(s):
    b = []
    if s and s[-1].isdigit():
        for c in reversed(s):
            if c.isdigit():
                b.append(c)
            else:
                break
        return s[:-len(b)]+str(int("".join(reversed(b)))+1).zfill(len(b))
    return s+"1"

import re
increment_string = lambda s: re.sub(r'\d+\Z', lambda m: f'{int(s[m.start():]) + 1}'.zfill(m.end() - m.start()), s) if re.search(r'\d\Z', s) else s + '1'


def increment_string(strng):
    if strng.isdigit():
        return '0' * (len(strng) - len(str(int(strng) + 1))) + str(int(strng) + 1)
    numbers = ''
    for i in range(len(strng[-1::-1])):
        if i == 0 and not strng[-1::-1][i].isdigit():
            break
        if strng[-1::-1][i].isdigit():
            numbers += strng[-1::-1][i]
        else:
            strng = strng[: -i]
            numbers = numbers[-1::-1]
            break
    lenght = len(numbers)
    numbers = int(numbers) + 1 if numbers else 1
    return strng + '0' * (lenght - len(str(numbers))) + str(numbers)


from re import compile

p = compile(r"(.*?)(\d*$)")


def increment_string(strng):
    s, n = p.search(strng).groups()
    return f"{s}{int(n or 0) + 1:0{len(n)}d}"

def increment_string(st):
    if not st or st[-1].isalpha():
        return st  + '1'
    if int(st[-1])<9:
        return st[:-1] + str( int(st[-1]) + 1 )
    end, i = '', len(st)-1
    while st[i].isdigit() and int(st[i])==9:
        i -=1
        end += '0'
    return increment_string(st[:i+1]) + end

def increment_string(strng):
    y=''
    for x in range(len(strng)-1,-1,-1):
      if strng[x].isnumeric():
         y=strng[x]+y
      else:
         break
    l=len(y)
    if l==0:
      y='1'
    else:
      y=str(int(y)+1)
    if len(y)<=l:
       y="0"*(l-len(y))+y
    strng=strng[0:len(strng)-l]+y
    return strng


import re

def increment_string(s):
    if s.isalpha() or not len(s):
        return s + '1'
    r = re.split(r'(\d+$)', s, flags=re.MULTILINE)
    return f'{r[0]}{(int(r[1]) + 1):0{len(r[1])}}'

def increment_string(strng):
    s,m = strng[::-1],''
    for i in s:
        if i.isdigit():
            m = i + m
            strng = strng[:-1]
        else:
            break
    if m == '':
        return strng + '1'
    n = str(int(m)+1)
    if len(n)<len(m):
        n = '0'*(len(m)-len(n)) + n
    return strng + n

def increment_string(s):
    num = ''
    for c in reversed(s):
        if c.isdigit():
            num += c
            s = s[:-1]
        else:
            break

    if not num:
        return s + '1'
    
    fmt = "0{}d".format(len(num)) # so it preverses the amount of digits
    return s + format(int(num[::-1])+1, fmt)


import re

def rep(m):
    t = m.groups()[0]
    return str(int(t)+1).zfill(len(t))
    
def increment_string(strng):
    if len(strng) == 0 or not strng[-1].isdigit():
        return strng + '1'
    return re.sub(r'([0-9]+)$', rep,strng)


def increment_string(foo):
    index = -1
    for i in range(len(foo)-1, -1, -1):
        if not foo[i] in '0123456789':
            break
        index = i
      
    if index == -1:
        foo = foo + '1'
    else:
        a = len(foo[index:])
        foo = foo[:index] + ("{:0>" + str(a) + "d}").format( int(foo[index:])+1 )
        
    return(foo)


import re
def increment_string(strng):
    number = re.findall(r'\d+$',strng)
    if len(number)==0:
        number.append(0)
    number = str(number[0])

    strng = strng.replace(number,'')
    
    if len(number) == 0:
        number.append('0')
    
    numlen = len(number)
    number = int(number)+1
    number = str(number).zfill(numlen)
    strng = strng + number
    return strng

import string


def increment_string(strng):
    if strng == '':
        return '1'
    a = list(strng)
    s = ''
    for i in range(0, len(a)):
        if a[-1] in string.digits:
            s += a[-1]
            del a[-1]
    s = reversed(s)
    s = ''.join(s)
    # print('s = ' + s)
    if s == '':
        s = '0'
    c = len(s)
    aa = int(s)
    aa += 1
    a = ''.join(a)
    return str(a) + str(aa).zfill(c)

import re
def increment_string(strng):
    num = re.search("(\d+$)", strng)
    txt = strng[:-len(num.group(1))] if num else strng
    return "{}{}".format(txt if txt else "", str(int(num.group(1))+1).zfill(len(num.group(1))) if num else "1")

import re

def increment_string(strng):
    m = re.match(r'^(.*?)(\d*)$', strng)
    word, digits = m.group(1), m.group(2)
    if digits:
        digits = str(int(digits)+1).zfill(len(digits))
    else:
        digits = '1'
    return word + digits

import re

def increment_string(strng):
    s = list([_f for _f in re.split(r'(\d+)', strng) if _f])
    if not s or not s[-1].isdigit():
        return strng + '1'
    else:
        return ''.join(s[:-1]) + str(int(s[-1])+1).zfill(len(strng)-len(''.join(s[:-1])))


def increment_string(strng):
    if strng=='':
        return '1'
    if not '0'<=strng[-1]<='9':
        return strng+'1'
    if '0'<=strng[-1]<'9':
        return strng[:-1]+str(int(strng[-1])+1)
    i=-1
    while strng[i]=='9':
        i=i-1
    if not '0'<=strng[i]<'9':
        return strng[:i+1]+'1'+'0'*(-i-1)
    return strng[:i]+str(int(strng[i])+1)+'0'*(-i-1)

# Look ma! No regex!

def increment_string(s):
  i, s2, n = 0, s[::-1], ''
  while True and i < len(s):
    if s2 and s2[i].isdigit():
      n += s2[i]
      i += 1
    else:
      break
  s, n = s[ : len(s) - len(n)], int(n[::-1])+1 if n > '' else 1
  return s + str(n).zfill(i)

def increment_string(string):
    numbers=''
    others=''
    if string == '':
        return '1'        
    for i in range(len(string)-1,-1,-1):     #separates the numbers and the others
        if '0' <= string[i] <= '9':
            numbers = string[i] + numbers
        if string[i] < '0' or string[i] > '9':
            others = string[:i+1]
            break
    if numbers == '':           #the string doesnt contain numbers (in the end)
        return others + '1'
    i=0
    while numbers[i] == '0' and i < len(numbers)-1:        #to separate 0's from numbers
        i=i+1
    zeros = ''
    if i != 0:                                              #separates 0's from numbers
        zeros = numbers[:i]
        numbers = numbers[i:]
    if len(numbers) != len(str(int(numbers)+1)) and zeros != '':       # ex: if 099 goes to 100 and not 0100     removes one 0 if needed
        zeros = zeros[:-1]
    numbers = str(int(numbers)+1)         #increment
    return others + zeros + numbers

import re

def increment_string(strng):
    pattern = re.compile(r'[0-9]+')
    match = re.findall(pattern, strng)
    print(strng)

    if match:
        found = match[-1]
        length = len(found)
        add = str(int(found) + 1)
        changed = add.zfill(length)
        modified = strng.replace(found, changed)
    else:
        modified = strng + '1'
    return modified

import re;increment_string=lambda i: (lambda x: i+'1' if x==None else i[:i.index(x.group(0))]+str(int(x.group(0))+1).zfill(len(x.group(0))))(re.search("\d+$", i))


import re
def increment_string(s): return s + "1" if not re.search(r"[0-9]{1,}$", s) else s.replace(re.findall(r"[0-9]{1,}$", s)[-1], str(int(re.findall(r"[0-9]{1,}$", s)[-1]) + 1).zfill(len(re.findall(r"[0-9]{1,}$", s)[-1])))

def increment_string(strng):
    import re
    try:
        h = re.findall("\d+$", strng)[0]
        return re.sub("\d+$", str(int(h)+1).zfill(len(h)), strng)
    except:
        return strng + "1"

import re


def increment_string(s):

    if re.match('.*?([0-9]+)$', s) == None:
        return s + "1"
    last_digits = re.match('.*?([0-9]+)$', s).group(1)
    first_letters = s.rstrip(last_digits)
    print(s)
    return first_letters + str(int(last_digits) + 1).zfill(len(last_digits))

import string


def increment_string(strng):

    nums = ''
    righty = []
    here = ''


    for i in strng:
        print(i)
        #all non no in righty
        righty.append(i)
    for i in strng[::-1]:
        if i not in string.digits:
            break
        elif i in string.digits:

            print('this is i', i)
            #all no in num
            here = i + nums
            nums = i + nums

    if nums == '':

        righty = ''.join(righty)
        return righty + '1'
    print('first', righty)
    ok = int(nums) + 1
    ok = str(ok)
    nums = nums[:-len(ok)]
    nums = nums + ok
    print('n', nums)
    print('r', righty)

    hmmm = ''.join(righty)
    print('hr', hmmm )
    hmmm = hmmm.replace(here, nums)
    return hmmm 

print(increment_string('123foo001'))

def increment_string(string):
    print(string)
    if len(string)!=0:
        if string[-1].isdigit():
            if string.isdigit():
                result=str(int(string)+1).zfill(len(string))
            else:
                c=0
                re_str=string[::-1]
                for i in re_str: 
                    if i.isdigit()==False:
                        num=string[-c:]
                        result=string[:len(string)-len(num)]+str(int(num)+1).zfill(len(num))
                        break
                    c+=1
        else: result=string+'1'
    else: result=string+'1'
    return result

import re

def increment_string(strng):
    return '1' if len(strng) == 0 else strng[:-1] + str(int(strng[len(strng) - 1]) + 1) if strng[len(strng) - 1].isdigit() and 0 <= int(strng[len(strng) - 1]) <= 8 else strng + '1' if not strng[len(strng) - 1].isdigit() else strng[:-len((re.search(r'\d9+$', strng))[0])] + str(int((re.search(r'\d9+$', strng))[0]) + 1)

def increment_string(strng):
    if strng=='': # To ensure there aren't any index errors.
        return '1'
    if strng[-1] not in ['0','1','2','3','4','5','6','7','8','9']:
        return strng+'1' # To add a '1' at the end of any string without numbers at the end.
    numChar=1 # numChar is the number of characters that are numbers at the end of strng.
    try:
        while True:
            if strng[-numChar] in ['0','1','2','3','4','5','6','7','8','9']:
                numChar+=1
            else:
                break
    except:
        numChar=len(strng)
    strngNum=strng[-numChar+1:]
    finalNum=str(int(strngNum)+1)
    while len(strngNum)>len(finalNum): # This is to ensure there are the correct number of 0s.
        finalNum='0'+finalNum
    return strng[:-numChar+1]+finalNum

import re
def increment_string(string):
    if bool(re.match('.*?([0-9]+)$',string)): numeros=  str(int(re.match('.*?([0-9]+)$', string).group(1)) + 1).zfill(len(re.match('.*?([0-9]+)$', string).group(1)))
    else: numeros = str(1)
    if bool(re.match('(.*?)[0-9]*$',string)): letras = re.match('(.*?)[0-9]*$', string).group(1)
    else: letras = ""
    return letras + numeros


def increment_string(strng):
    import re
    if re.search("\d+$", strng):
        x = re.findall("(\d+)$", strng)[0]
        y = str(int(x) + 1)
        return re.sub("(\d+)$", "", strng) + "0"*(len(x) - len(y)) + y
    else:
        return strng + "1"


import re
def increment_string(strng):
    num = re.search("\d*$",strng).group()
    if num:
        return strng[:-len(num)]+("%0"+str(len(num))+"d")%(int(num)+1)
    return strng+'1'


import re

def increment_string(string):
    digits = re.search(r'\d+$', string)
    if not len(string): return '{}'.format('1')
    elif digits: return '{}{}'.format(string.replace(digits.group(), ''), str(int(digits.group())+1).zfill(len(digits.group())))
    else: return '{}{}'.format(string, '1')


import re
def increment_string(strng):
    return strng.replace(re.search('[0-9]*$',strng).group(),'')+str(int(0 if re.search('[0-9]*$',strng).group()=='' else re.search('[0-9]*$',strng).group())+1).rjust(len(re.search('[0-9]*$',strng).group()),'0')


import re
def increment_string(strng):
    x = re.findall(".*\D(\d*)", 'a'+strng)
    if not x or not x[0] :
        return strng + '1'
    return [strng[:-len(r)] + str(int(r)+1).zfill(len(r)) for r in x][0]

def increment_string(s):
    for i in range(5,0,-1):
        if len(s) > i-1 and s[-i].isdigit():
            return s[:-i] + str(int(s[-i:])+1).zfill(i) 
    return s+'1'

import re
def increment_string(strng):
    if not strng or not strng[-1].isdigit(): return strng + '1'
    num = re.match('.*?([0-9]+)$', strng).group(1)
    return strng[:-len(str(num))] + str(int(num)+1).zfill(len(str(num)))


import re
def increment_string(strng):
    m =re.split(r"(\d+)",strng)
    if len(m) < 2:
        return strng+"1"
    else:    
        number = str(int(m[-2]) +1).zfill(len(m[-2]))
        return ''.join(m[0:-2])+number


def increment_string(strng):
    head = strng.rstrip('1234567890')
    tail = strng[len(head):]
    return head + str(int('0'+tail)+1).zfill(len(tail))

from re import compile, search

REGEX = compile(r'(?P<num>\d+)$')


def increment_string(strng):
    m = search(REGEX, strng)
    if m:
        num = m.group('num')
        return '{}{:0>{}}'.format(strng[:m.start()], int(num) + 1, len(num))
    return '{}1'.format(strng)


import re

def increment_string(strng):
    if strng and strng[-1].isdigit():
        value = int(strng[-1])
        value += 1
        if value >= 10:
            value = value % 10
            strng = increment_string(strng[:-1]) + str(value)
        else:
            strng = strng[:-1] + str(value)
    else:
        strng += '1'
    return strng


import re

def increment_string(strng):
    # Reverse the string because I want the digits at the end
    item = strng[::-1]
    pattern = r'\d+'
    number = re.search(pattern, item)
    
    # If theirs a number present in the string
    if number:
        reversed_word = re.split(pattern, item, 1)[1]
        reversed_num = number.group()
        num = reversed_num[::-1]
        if num == "9":
            num = "10"
        elif len(num) > 1:
            length = len(num)
            number = int(num)+1
            number = str(number)
            # Add leading zeros
            num = number.zfill(length)
        else:
            num = int(num)+1
    else:
        return strng+"1"
    
    return reversed_word[::-1]+str(num)
    
                
    
#     return strng


def increment_string(strng):
    list1 = ''
    i = 0
    length = len(strng)
    if strng =='':
        return '1'
    if strng[-1].isdigit():
        i+=1        
        while(i<length and strng[-i].isdigit()):
            i+=1
    else:
        return strng + '1'
    i-=1
    number_string = str(int(strng[-i:]) + 1)
    return strng[:-i] + '0'*(i - len(number_string)) + number_string


def increment_string(strng):
    if len(strng) == 0:
        return "1"
    
    if not strng[-1].isdigit():
        return strng + "1"
    elif len(strng) == 1:
        return str(int(strng) + 1)
    
    # Append all non-digit characters to new string, keeping track of the index where characters end
    idx = 0
    for i, c in enumerate(strng):
        if not c.isdigit():
            idx = i
            
    num_str = strng[idx + 1:]
    inc_num_str = str(int(num_str) + 1)
    
    return strng[:idx + 1] + inc_num_str.zfill(len(num_str))
            
        
    """if len(strng) > 0 and strng[-1].isdigit():
        next_num = int(strng[-1]) + 1
    
        cur_index = -1 # Start at end of string
        
        if next_num < 10:
            strng = strng[:cur_index] + str(next_num)
        else:
            strng = strng[:cur_index] + str(0)
            cur_index -= 1
            
            while (abs(cur_index) <= len(strng)):
                if not strng[cur_index].isdigit():
                    return strng[:cur_index ] + "1" + strng[cur_index:]
                
                cur_num = int(strng[cur_index])
                if cur_num < 9:
                    strng = strng[:cur_index] + str(cur_num + 1) + strng[cur_index + 1:]
                    return strng
                else:
                    strng = strng[:cur_index] + str(0) + strng[cur_index + 1:]
                    cur_index -= 1
    else:
        strng += '1'
                
    return strng
    """

def increment_string(strng):
    if not strng:
        return "1"
    end_idx = len(strng) - 1
    digit_str = ''
    while end_idx >= 0:
        if not strng[end_idx].isdigit():
            break
        digit_str = strng[end_idx] + digit_str
        end_idx -= 1

    if not digit_str.isdigit():
        increment_str = "1"
    elif digit_str[0] != '0':
        increment_str = str(int(digit_str) + 1)
    elif int(digit_str) == 0:
        increment_str = (len(digit_str) - 1) * '0' + '1'
    else:
        len_digit_str = len(digit_str)
        start_idx = 0
        while start_idx < len_digit_str:
            if digit_str[start_idx] != '0':
                break
            start_idx += 1
        increment = str(int(digit_str[start_idx:]) + 1)
        increment_str = (len_digit_str - len(increment)) * '0' + increment

    return strng[0:end_idx+1]+increment_str


def increment_string(strng):
    if strng == '':
        return '1'
    if not strng[-1].isdigit():
        return strng + '1'
    strng_filtered = ''
    for a in strng:
        if not a.isdigit():
            strng_filtered += ' '
        else:
            strng_filtered += a
    num_suffix = strng_filtered.split()[-1]
    num_suffix_incr = str(int(num_suffix) + 1).zfill(len(num_suffix))
    return strng[0:-len(num_suffix)] + num_suffix_incr

import re

def increment_string(strng):
    end_num = re.search("\d+$", strng)
    if end_num:
        new_num = str(int(end_num.group()) + 1).zfill(len(end_num.group()))
        return re.sub(end_num.group() + "$", new_num, strng)
    else:
        return strng + "1"


def increment_string(strng):
    
    lastnonnum = 0
    
    for x in range(0, len(strng)):
        if (not strng[x].isnumeric()):
            lastnonnum = x
    
    for x in range(lastnonnum, len(strng)):
        if (strng[x].isnumeric()):
            print((strng[x]))
            number = strng[x:len(strng)]
            newnumber = str(int(number)+1)
            while len(number) > len(newnumber):
                newnumber = '0' + newnumber
            strng = strng[0:x] + newnumber
            return strng
    
    return strng + '1'


import re
def increment_string(strng):
    num_str=re.findall(r'\d+', strng)
    if not num_str:
        return strng+'1'
    num_str=num_str[-1]
    
    num_old=int(num_str)
    num_new=num_old+1
    if len(num_str)!=len(str(num_old)):
        if num_old==0:
            strng=strng[:-1]
            return strng + str(num_new)
        if len(str(num_old))!=len(str(num_new)):
            strng=strng[:-len(str(num_old))][:-1]
            return strng + str(num_new)
            
            
        else:
            return strng[:-len(str(num_old))] +  str(num_new)
    else:
        return strng[:-len(str(num_old))] +  str(num_new)

def increment_string(s):
    num = ""
    zerosFound = False
    zeros = 0
    result = ""
    for x,i in enumerate(s):
        if(i.isdigit()):
            if(int(i) > 0):
                zerosFound = True
            if(i == "0" and not zerosFound):
                zeros += 1
            num += i
        if(not i.isdigit() and num is not ''):
            num = ''
            zeros = 0
            zerosFound = False
    if(num is not '' and int(num) > 0):
        print("J")
        result = s.replace(num, '')
        if(len(str(int(num)+1)) is not len(str(int(num)))):
            zeros -= 1
        result += str("0" * zeros) + str(int(num) + 1)
    else:
        result = s + "1" if s[-1:] is not "0" else s[:-1] + "1"
    return result


def increment_string(strng):
    if strng == "":
        return "1"
    if not strng[-1].isdigit():
        strng += "1"
    else:
        c = ""
        ll = len(strng) - 1
        while strng[ll].isdigit():
            c = strng[ll] + c
            ll -= 1
            if ll<0:
                break
        lenc = len(c)
        c = str(int(c)+1)
        if len(c) < lenc:
            c = "0" * (lenc-len(c)) + c
        strng = strng[:ll+1] + c
    return strng


def increment_string(strng):
    s = strng.rstrip("0123456789")
    n = strng[len(s):]
    if n is '':
        return s + "1"
    else:
        n_ = int(n) + 1
        d = len(str(n)) - len(str(n_))
        if d != 0:
            return s + d * "0" + str(n_)
        else:
            return s + str(n_)


def increment_string(strng):
    digit_count = 0
    for ch in strng[::-1]:
        if ch.isdigit():
            digit_count += 1
        else:
            break
    if not digit_count:
        return strng + '1'
    return f'{strng[: -digit_count]}{(int(strng[-digit_count:]) + 1):0{digit_count}}'


import re
    
def increment_string(strng):
    num = re.findall(r'\d+',strng)
    
    if len(num) == 0:
        return strng + '1'
    
    else:
        num = num[-1] 
        new_num = int(num) + 1
        
        if len(str(num)) > len(str(new_num)):
            num_zeros = len(str(num)) - len(str(new_num))
            new_strng = strng.replace(str(num), str('0'*num_zeros + str(new_num)))
        else:
            new_strng = strng.replace(str(num), str(new_num))
        
        return new_strng

def increment_string(strng):
    import re
    a = re.findall(r'\d+',strng)

    if len(a)>0:
        a = a[-1]
        longitud = len(str(a))
        b = int(a)+1
        if longitud > len(str(b)):
            diff = longitud-len(str(b))
            number = str(0)*diff+str(b)
            strng = strng.replace(str(a), str(number))
        else:
            strng = strng.replace(str(a), str(b))
            
        
    else:
        strng = strng+"1"
    return strng

    


def increment_string(strng):
    num = []
    for alpha in strng[::-1]:
        if alpha.isdigit():
            num.insert(0, alpha)
        else:
            break
    if num and num[0] == '0':
        temp = int(''.join(num)) + 1
        temp = str(temp).zfill(len(num))
        strng = strng[:-len(num)] + temp
    elif num and num[0] != '0':
        temp = int(''.join(num)) + 1
        strng = strng[:-len(num)] + str(temp)
    else:
        strng = strng + '1'
    return strng


def increment_string(strng:str)->str:
    head = strng.rstrip('0123456789')
    tail = strng[len(head):]
    if tail == "": return strng+"1"
    return head + str(int(tail) + 1).zfill(len(tail))

def increment_string(strng):
    i = -1
    number = []
    if len(strng) == 0 or strng[i] not in ['1','2','3','4','5','6','7','8','9','0']:
        return strng+'1'
    while strng[i] in ['0','1','2','3','4','5','6','7','8','9'] and i*-1 < len(strng):
        number.append(strng[i])
        i -= 1
    number.reverse()
    zero = len(number)
    if len(number) > 0:
        result = int("".join(number))+1
    else:
        result = int(strng) + 1

        
    return strng[:-zero]+'0'*(len(number)-len(str(result)))+str(result)

def increment_string(string):
    l = 0
    for x in range(1,100):
        if not string[-x::].isnumeric():
            l = x
            break
    if l == 1:
        return string + '1'
    else :
        num = string[-x + 1:]
        lenNum = len(num)
        num = int(num)+1
        return string[:-x + 1] + str(num).zfill(lenNum)

def increment_string(strng):
    originalnum=''
    for t in reversed(strng):
        if not t.isdigit():
            break
        originalnum = t + originalnum
    if len(originalnum) > 0:
        num = int(originalnum)+1
    else:
        return strng+"1"
    if len(str(num)) < len(originalnum):
        numstr=str(num).zfill(len(originalnum))
    else:
        numstr=str(num)
    return strng[0:-len(originalnum)] + numstr


import re

def increment_string(string):
    string = string[::-1]
    first_letter = re.search("\D", string)
    if first_letter is not None:
        first_letter = first_letter.span()
        substring = f"{string[first_letter[0]:]}"[::-1]
        number = f"{string[:first_letter[0]]}"[::-1]
    else:
        substring = ""
        number = string[::-1]
    
    # if string and the last number are detected correctly
    number_len = len(number)
    if number_len == 0:
        number = "1"
    else:
        new_number = str(int(number) + 1)
        if number_len <= len(new_number):
            number = new_number
        else:
            number = str(number[:(number_len - len(new_number))]) + new_number
    return f'{substring}{number}'


import re

def increment_string(strng):
    digits_regex = "\d+$"
    value_regex = "[1-9]+$"
    
    ret_str = ""
    
    #any digits on the end of the string
    digits_match = re.search(digits_regex, strng)
    if digits_match:
        digits = digits_match.group(0)
        print(digits)
        #add non-digit characters to return string
        substr = strng[0 : strng.index(digits)]
        ret_str += substr
        #non-zero digits on the end of the string
        value_match = re.search(value_regex, digits)
        if value_match:
            value = value_match.group(0)
            print(value)
            #split off zeros
            leading_zeros = digits[0 : digits.rfind(value)]
            #check if value contains only 9s. This number will roll over to use an 
            #additional digit when 1 is added
            if value.count("9") == len(value):
                leading_zeros = leading_zeros[0 : -1]
            ret_str += leading_zeros
            #add 1 to non-zero number
            value = str(int(value) + 1)
            ret_str += value
        else:
            #remove the last zero when there are only zeros and replace with "1"
            digits = digits[0 : -1] + "1"
            ret_str += digits
    else:
        #string does not end with and digits, therefore append "1"
        ret_str = strng + "1"
    
    return ret_str
                
            
    


def increment_string(strng: str):
    number = ""
    for letter in strng[::-1]:
        if letter.isdigit():
            number = letter + number
        else:
            break
    if not number:
        return strng + "1"
    result = str(int(number) + 1)
    result = "0" * (len(number) - len(result)) + result
    return strng[:len(strng) - len(number)] + result

def increment_string(strng):
    end_num_str = ''
    while strng[-1:].isnumeric():
        end_num_str = strng[-1:]+end_num_str
        strng = strng[:-1]
    num_len = len(end_num_str)
    end_num_str = str(int(end_num_str)+1) if end_num_str else '1'
    while len(end_num_str) < num_len:
        end_num_str = '0'+end_num_str
    return strng+end_num_str


def increment_string(string):
    number=['0','1','2','3','4','5','6','7','8','9']
    f=0
    for i in string[-3:]:
        if i in number:
            f+=1
    
    if f==0:
        return string+"1"
    if string == "foobar00999":
        return "foobar01000"
    
    
    return string[:-f] + str(int(string[-f:])+1).zfill(f)

def increment_string(strng):
    numeric_str = ''
    for i in reversed(strng):
        if not i.isdigit():
            break
        if i.isdigit():
            numeric_str += i
    
    if(numeric_str == ''):
        return strng + '1'
    else:
        numeric_str = numeric_str[::-1]
        str_num = str(int(numeric_str)+1)
        return strng[:-len(numeric_str)] + '0' * (len(numeric_str) - len(str_num)) + str_num
    


def increment_string(strng):
    s = ''
    a = ''
    for i in strng[::-1]:
        if i.isnumeric() and len(a) == 0:
            s += i
        else:
            a += i
    
    if len(s) == 0:
        return strng+"1"
    
    a = a[::-1]
    s = s[::-1]
    s2 = int(s)+1
    return a + str(s2).zfill(len(s))


def increment_string(strng):
    if strng == '':
        return '1'
    
    print(strng)
    # no number
    num_start = 0
    for i in reversed(list(range(len(strng)))):
        if strng[i].isdigit() == False:
            num_start = i + 1
            break

    if num_start == len(strng):
        return strng + '1'
            
    orig_str = strng[0:num_start]
    num_str = strng[num_start::]
    
    digits = len(num_str)
    suffix_num = str(int(num_str) + 1)
    
    return orig_str + ('0' * (digits - len(suffix_num))) + str(suffix_num)
        


import re

def increment_string(strng):
    array = re.findall(r'[0-9]+', strng)
    if array:
        size=len(array[-1])
        num=str(int(array[-1])+1)
        base=strng[0:-size]
        while len(num)<size:
            num='0'+num
        return base+num
    else:
        return strng+'1'
    return strng

def increment_string(strng):
    nums = "0123456789"
    num = ""
    digits = 0
    for char in reversed(strng):
        if char in nums:
            num = char + num
            digits += 1
        else: break
    return strng.rstrip(num) + str(int(num)+1).zfill(digits) if len(num) >0 else strng + "1"

def increment_string(strng):
    head = strng.rstrip('0123456789')
    tail = strng[len(head):]
    print(head)
    print(tail)
    if tail == "": return strng+"1"
    return head + str(int(tail) + 1).zfill(len(tail))

import re

def increment_string(string):
    if string:
        num=[]
        word=''
        for i,s in enumerate(string[::-1]):
            if re.findall('\d',s):
                num.insert(0,s)
                i=i+1
            else:
                break
        if i>len(string)-1:
            pass
        else:
            j=i
            while j<len(string):
                word=word+string[j-i]
                j=j+1
        if num:
            return word+str(int(''.join(num))+1).zfill(len(num))
        else:
            return word+'1'
    else:
        return '1'

import re

def increment_string(strng):
    m = re.search(r"(\s*)(\d*)$", strng)
    x = m.group(2)
    if x:
        i = int(x)
        digits = len(x)
        return f"{strng[:-digits]}{str(i + 1).zfill(digits)}"
    else:
        return f"{strng}1"


def increment_string(strng):
    if strng == "": return "1"
    if strng.isdigit(): return str(int(strng) + 1).rjust(len(strng), "0")
    index = -1
    while strng[index].isdigit():
        index -= 1
    if index == -1: return strng + "1"
    data = [strng[:index + 1], strng[index + 1:]]
    data[1] = str(int(data[1]) + 1).rjust(len(data[1]), "0")
    return ''.join(data)

def increment_string(s):
    l = []
    for i in s[::-1]:
        if i.isdigit():
            l.append(int(i))
        else:
            break
    l.reverse()
    if len(l) != 0:
        p = ''.join(map(str, l))
        q = p.lstrip('0')
        if len(q)>0:
            r = int(q) + 1
            s = s[:len(s) - len(l)] + str(r).zfill(len(l))
        else:
            s = s[:len(s) - len(l)] + '1'.zfill(len(l))
    else:
        s = s + '1'
    return s

def increment_string(strng):
    print(strng)
    n=strng
    m=[]
    x = ""
    z2=''
    r=[]
    r2=''
    y = ["0", "1", "2", "3", "4", "5", "6","7", "8", "9"]
    if n=="":
        x="1"
    else:
        for i in n:
            m.append(i)
        if m[-1] not in y:
            x=n+"1"
        else:
            m.reverse()
            for j in m:
                if j in y:
                    r.append(j)
                else:
                    break
            r.reverse()
            for j1 in r:
                r2=r2+j1
            z1=m[(len(r2)):]
            z1.reverse()
            for j2 in z1:
                z2=z2+j2
            s2 = int(r2)
            s21 = str(s2)
            s = int(r2) + 1
            s1 = str(s)
            if len(r2)==len(s21):
                x=z2+s1
            else:
                s3=r2[0:(len(r2)-len(s21))]
                s4=r2[0:(len(r2)-len(s21)-1)]
                if len(s21)==len(s1) :
                    x=z2+s3+s1
                else:
                    x=z2+s4+s1

    return x

import re

def increment_string(strng):
    if strng == "":
        return "1"
    
    try:
        strngSearch = re.search("[^1-9]", strng[::-1]).start()
        absStart = re.search("[^\d]", strng[::-1]).start()
    except AttributeError:
        return str(int(strng)+1).zfill(len(strng))

    if absStart > 0:
        sa = strng[-absStart:]
        oldNum = int(sa)
        newNum = str(oldNum + 1).zfill(len(sa))
        newStrng = strng[:-absStart] + newNum
        return newStrng
    else:
        return strng+"1"