forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegex_As_4.py
More file actions
14 lines (12 loc) · 750 Bytes
/
Regex_As_4.py
File metadata and controls
14 lines (12 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
''' Fill in the code to check if the text passed includes a possible U.S. zip code,
formatted as follows: exactly 5 digits, and sometimes, but not always, followed
by a dash with 4 more digits. The zip code needs to be preceded by at least one
space, and cannot be at the start of the text. '''
import re
def check_zip_code (text):
result = re.search(r" (\d{5})([- ])?(\d{4})?", text)
return result != None
print(check_zip_code("The zip codes for New York are 10001 thru 11104.")) # True
print(check_zip_code("90210 is a TV show")) # False
print(check_zip_code("Their address is: 123 Main Street, Anytown, AZ 85258-0001.")) # True
print(check_zip_code("The Parliament of Canada is at 111 Wellington St, Ottawa, ON K1A0A9.")) # False