forked from arvimal/100DaysofCode-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_with_pipes.py
More file actions
31 lines (23 loc) · 865 Bytes
/
match_with_pipes.py
File metadata and controls
31 lines (23 loc) · 865 Bytes
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
#!/usr/bin/env python3
import re
import sys
def check_words(string=None):
"""
Check your input string for specific words
such as "Britain", "Ireland", "Wales", "Scotland"
"""
if string is None:
print("We need a string to work on.")
sys.exit(-1)
else:
# IMPORTANT: DO NOT PUT SPACES IN BETWEEN PIPES
# ie. DO NOT use re.compile("Britain | Ireland | Wales | Scotland")
british_isles_regex = re.compile("Britain|Ireland|Wales|Scotland")
search_output = british_isles_regex.search(string)
try:
if search_output.group():
print("\n - Your input contains {}".format(search_output.group()))
except AttributeError:
print("\n - Your input does not match the pattern.")
check_words("I am calling from Ireland")
check_words("I am not here")