Skip to content

Commit 7f8e651

Browse files
authored
Add files via upload
1 parent 0c64d85 commit 7f8e651

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

phoneAndEmail.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! python3
2+
# phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard.
3+
4+
import pyperclip, re
5+
6+
phoneRegex = re.compile(r'''(
7+
(\d{3}|\(\d{3}\))? # area code
8+
(\s|-|\.)? # separator
9+
(\d{3}) # first 3 digits
10+
(\s|-|\.) # separator
11+
(\d{4}) # last 4 digits
12+
(\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
13+
)''', re.VERBOSE)
14+
15+
# Create email regex.
16+
emailRegex = re.compile(r'''(
17+
[a-zA-Z0-9._%+-]+ # username
18+
@ # @ symbol
19+
[a-zA-Z0-9.-]+ # domain name
20+
(\.[a-zA-Z]{2,4}){1,2} # dot-something
21+
)''', re.VERBOSE)
22+
23+
# Find matches in clipboard text.
24+
text = str(pyperclip.paste())
25+
26+
matches = []
27+
for groups in phoneRegex.findall(text):
28+
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
29+
if groups[8] != '':
30+
phoneNum += ' x' + groups[8]
31+
matches.append(phoneNum)
32+
for groups in emailRegex.findall(text):
33+
matches.append(groups[0])
34+
35+
# Copy results to the clipboard.
36+
if len(matches) > 0:
37+
pyperclip.copy('\n'.join(matches))
38+
print('Copied to clipboard:')
39+
print('\n'.join(matches))
40+
else:
41+
print('No phone numbers or email addresses found.')

phoneandEmail1st try.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#! python3
2+
# phoneAndEmail.py
3+
4+
import pyperclip, re
5+
6+
7+
phoneRegex = re.compile(r'''(
8+
(\d{3}|\(\d{3}\))? # area code
9+
(\s|-|\.)? # seperator
10+
(\d{3}) # first 3 digits
11+
(\s|-|\.) # seperator
12+
(\d{4}) # last 4 digits
13+
(\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
14+
)''', re.VERBOSE)
15+
16+
17+
# Create email regex.
18+
emailRegex = re.compile(r'''(
19+
[a-zA-Z0-9._%+-]+ # username
20+
@ # @ symbol
21+
[a-Za-Z0-9.-]+ # domain name
22+
(\.[a-zA-Z] (2,4)) # dot-something
23+
)''', re.VERBOSE)
24+
25+
26+
# Find matches in clipboard text.
27+
text = str(pyperclip.paste())
28+
matches = []
29+
for groups in phoneRegex.findall(text):
30+
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
31+
if groups[8] != '':
32+
phoneNum += ' x' + groups[8]
33+
matches.append(phoneNum)
34+
for groups in emailRegex.findall(text):
35+
matches.append(groups[0])
36+
37+
# Copy results to the clipbiard.
38+
if len(matches) > 0:
39+
pyperclip.copy('\n'.join(matches))
40+
print('Copies to clipboard:')
41+
print('\n'.join(matches))
42+
else:
43+
print('No phone numbers or email addresses found.')

phoneandEmailcopy.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# phoneAndEmail.py - Finds phone numbers and email adresses on the clipboard
2+
3+
import pyperclip, re
4+
5+
# Create PhoneRegex object and EmailRegex Object
6+
phoneRegex = re.compile(r'''(
7+
(\d{3}|\(\d{3}\))? # area code
8+
(\s|-|\.)? # separator
9+
(\d{3}) # first 3 digits
10+
(\s|-|\.) # separator
11+
(\d{4}) # last 4 digits
12+
(\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
13+
)''', re.VERBOSE)
14+
15+
emailRegex = re.compile(r'''(
16+
[a-zA-Z0-9._%+-]+ # username
17+
@ # @ symbol
18+
[a-zA-Z0-9.-]+ # domain name
19+
(\.[a-zA-Z]{2,4}) # dot-something
20+
)''', re.VERBOSE)
21+
22+
# Copy the input from the clipboard and use it to search
23+
text = str(pyperclip.paste())
24+
matches = []
25+
for groups in phoneRegex.findall(text):
26+
phoneNum = '-'.join([groups[1], groups[3], groups[5]])
27+
if groups[8] != '':
28+
phoneNum += ' x' + groups[8]
29+
matches.append(phoneNum)
30+
for groups in emailRegex.findall(text):
31+
matches.append(groups[0])
32+
33+
# Paste input back to clipboard
34+
if len(matches) > 0:
35+
pyperclip.copy('\n'.join(matches))
36+
print('All copied to Clipboard : ')
37+
print('\n'.join(matches))
38+
else:
39+
print('No phone numbers or emails was found! ')

0 commit comments

Comments
 (0)