-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
32 lines (27 loc) · 794 Bytes
/
utils.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
from enum import Enum
import re
class FindOptions(Enum):
WORD = 0
REGEX= 1
def findWords(searchWords:[[]], text, trueIfAll=False):
found = False
for search in searchWords:
word = search[0]
matchFound = False
if search[1]==FindOptions.WORD:
result = re.search(rf'\b{word}\b',text, re.IGNORECASE)
matchFound = result is not None
elif search[1]==FindOptions.REGEX:
result = re.search(rf'{word}', text, re.IGNORECASE)
matchFound = result is not None
else:
assert False
if matchFound:
found = True;
if not trueIfAll:
break
else:
if trueIfAll:
found=False
break;
return found