You are viewing a single comment's thread. Return to all comments →
The best I can do is 2 RE. Please tell me if you could do it with a single RE:
import re n=int(input()) l=[input() for i in range(n)] for s in l: m1=re.fullmatch(r'[456]\d{3}((?P<sep>-?)\d{4})((?P=sep)\d{4}){2}', s) s2=s.replace('-', '') m2=re.search(r'(?P<digit>\d)(?P=digit){3}',s2) if m1 and not m2: print('Valid') else: print('Invalid')
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →
The best I can do is 2 RE. Please tell me if you could do it with a single RE: