-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregex.py
More file actions
25 lines (17 loc) · 750 Bytes
/
regex.py
File metadata and controls
25 lines (17 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import re
def multi_re_find(patterns,phrase):
for pat in patterns:
print("Searching for pattern: {}".format(pat))
print(re.findall(pat,phrase))
print("\n")
test_phrase = 'sdsd..sssddd..sdddsddd...dsds...dsssss...sdddd'
test_patterns = ['sd*'] # this means zero or more ds
multi_re_find(test_patterns, test_phrase)
test_patterns = ['sd?'] # this means zero or one ds
multi_re_find(test_patterns, test_phrase)
test_patterns = ['sd+'] # this means one or more ds
multi_re_find(test_patterns, test_phrase)
test_patterns = ['sd{1,3}'] # this means one to three ds
multi_re_find(test_patterns, test_phrase)
test_patterns = ['s[sd]+'] # this means one or more either s or d
multi_re_find(test_patterns, test_phrase)