-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathproject_1.py
47 lines (32 loc) · 1.08 KB
/
project_1.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
33
34
35
36
37
38
39
40
41
42
43
#E-mail and phone number extractor
import pyperclip
import re
#Text containing email's and phone number to be pasted from clipboard
text = str(pyperclip.paste())
#Regular expression for phone numbers
phone_regex = re.compile(r'''(
(\d{3}|\(\d{3}\))? # Non greedy approach for area code
(\s|-|\.)? # hypen or a dot (Phone number format)
(\d{3}) # first 3 digit
(\s|-|\.)? # seperator
(\d{4}) # Last 4 digit
)''', re.VERBOSE)
email_regex = re.compile(r'''(
[a-zA-Z0-9._%+-]+ # Username
@ # symbol
[a-zA-Z0-9.-]+ # domain name
(\.[a-z{2,4}]) # dot-something
)''', re.VERBOSE)
match =[] # list for storing all the matched found
for groups in phone_regex.findall(text):
phone_number = '-'.join([groups[1],groups[3],groups[5]])
match.append(phone_number)
for groups in email_regex.findall(text):
match.append(groups[0])
# Copy results to clipboard
if len(match)>0:
pyperclip.copy('\n'.join(match))
print ('Copied to clipboard')
print ('\n'.join(match))
else:
print ('Nothing found')