Skip to content

Commit

Permalink
Regex and Parsing!
Browse files Browse the repository at this point in the history
  • Loading branch information
snehalmastud authored Feb 23, 2020
1 parent e034916 commit c7c9d5e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Regex and Parsing/Validating Credit Card Numbers/Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import re
for i in range(int(raw_input())):
S = raw_input().strip()
pre_match = re.search(r'^[456]\d{3}(-?)\d{4}\1\d{4}\1\d{4}$',S)
if pre_match:
processed_string = "".join(pre_match.group(0).split('-'))
final_match = re.search(r'(\d)\1{3,}',processed_string)
print 'Invalid' if final_match else 'Valid'
else:
print 'Invalid'

0 comments on commit c7c9d5e

Please sign in to comment.