-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcar_registration.py
36 lines (31 loc) · 1.09 KB
/
car_registration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#car registration validtor
import re
#pattern = "[A-Z](([A-Z]\d{2}|\d{1,3})[A-Z]{3}|[A-Z]{2}\d{1,3}[A-Z]?$)"
pattern = """
[A-Z] #single letter
#followed by either:
(
(
[A-Z] #single letter
\d{2} #2 digits
| #or
\d{1,3} #between 1 and 3 digits
)
#followed by:
[A-Z]{3} #3 letters
| #or
[A-Z]{2} #two letters
\d{1,3} #between 1 and 3 digits
[A-Z]? #zero or one letters
)$
"""
finished = False
while not finished:
car_registration = input("Please enter your car registration: ")
if len(car_registration) == 0:
finished = True
else:
if re.match(pattern,car_registration,re.VERBOSE):
print("Valid car registration")
else:
print("Invalid car registration")