How to use a variable inside match regular expression in Python

1 Answer

0 votes
import re

s = "123456"
N = 6
exp = r"\d{" + str(N) + r"}\Z"
m = re.match(exp, s)

if m:
    print("True")
else:
    print("False")


'''
run:

True

'''

 



answered Jun 30, 2018 by avibootz
...