-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
50 lines (44 loc) · 1.46 KB
/
main.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
44
45
46
47
48
49
50
""""
Made by 0xHaris
"""
import pyperclip as pc
import re
def input(filename):
with open(filename, 'r') as f:
pc.copy("".join(f.readlines())) #copying the file content to the clipboard
return pc.paste()
def phone_extractor(content):
phone_regex = re.compile(r"""( #regex for US-based phone numbers
(\d{3}|\(\d{3}\))? #areacode
(\s|-|\.)? #seperator
(\d{3}) #first 3 digits
(\s|-|\.) #seperator
(\d{4}) #last 4 digits
)""", re.VERBOSE | re.DOTALL)
mo = phone_regex.findall(str(content)) # make a list of numbers found
return mo
def email_extractor(content):
email_regex = re.compile(r'''(
[a-zA-Z0-9._%+-]+ #username
@ #@symbol
[a-zA-Z0-9.-]+ #domain name
(\.[a-zA-Z]{2,4}) #dot-something
)''', re.VERBOSE)
mo2 = email_regex.findall(content)
return mo2
def main():
text = input("essay.txt")
matches = []
for groups in phone_extractor(text):
phoneNum = "-".join([groups[1], groups[3], groups[5]])
matches.append(phoneNum)
for groups in email_extractor(text):
matches.append(groups[0])
return matches
if __name__ == '__main__':
a = main()
for i in a:
if re.fullmatch(r'\d{3}-\d{3}-\d{4}', i.replace("(","").replace(")","")):
print(f"These are the phone numbers found:{i}\n")
else:
print(f"These are the email addresses found:{i}\n")