if m:
    lim = ''
for i, n in enumerate(s):
    lim = lim + n
if re.match('{0}\\d{{{0}}}$'.format(lim), s):
    return True
elif int(s[0:i + 1]) > len(s[i + 1:]):
    return False
print(checkNum('3123'))
print(checkNum('1234567'))
print(checkNum('100123456789'))
print(checkNum('9123456789'))
Using a regular expression backreference as part of the regular expression in Python