-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07.py
More file actions
33 lines (29 loc) · 813 Bytes
/
Copy path07.py
File metadata and controls
33 lines (29 loc) · 813 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
32
#! python3
import re, pyperclip
phoneRegex = re.compile(r'''(
(\d{3}|\(\d{3}\))?
(\s|-|\.)?
(\d{3})
(\|-|\.)
(\d{4})
(\s*(ext|x|ext.)\s*(\d{2,5}))?
)''', re.VERBOSE)
emailRegex = re.compile(r'''(
[a-zA-Z0-9._%+-]+ #username
@ # @symbol
[a-zA-Z0-9.-]+ #domain name
(\.[a-zA-Z]{2,4}) # dot-something
)''', re.VERBOSE)
text = str(pyperclip.paste())
matches = []
for groups in phoneRegex.findall(text):
print('groups:'+ str(groups))
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
if groups[8] != '':
phoneNum += ' x' + groups[8]
matches.append(phoneNum)
print('matches: ' + str(matches))
for groups in emailRegex.findall(text):
print('groups:'+ str(groups))
matches.append(groups[0])
print('matches: ' + str(matches))