Skip to content

Commit e38e673

Browse files
authored
changed searching to regular expression
1 parent c1b8371 commit e38e673

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

utls.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from itertools import tee
2-
2+
import re
33

44
def scrap(wrds):
5-
s = set()
5+
if isinstance(wrds, str):
6+
wrds = wrds.split(' ')
7+
data = set()
8+
pattern = re.compile(r'[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+')
69
for wrd in wrds:
7-
splited_wrd = wrd.split(' ')
8-
for i in range(len(splited_wrd)):
9-
wrds_indexed = splited_wrd[i]
10-
if ('@' in wrds_indexed and '.' in wrds_indexed) and (len(wrds_indexed) > 7):
11-
s.add(wrds_indexed)
12-
yield from s
10+
matches = pattern.search(str(wrd))
11+
try:
12+
data.add(matches.group(0))
13+
except AttributeError:
14+
pass
15+
yield from data
16+
1317

1418

1519
def files():

0 commit comments

Comments
 (0)