#! python3
# phoneAndEmail.py - Finds phone number and email addresses on the clipboard.
import pyperclip, re
phoneRegex = re.compile(r'''(
(\d{3}|\(\d{3}\))?
(\s|-|\.)?
(\d{3})
(\s|-|\.)
(\d{4})
(\s*(ext|x|ext.)\s*(\d{2,5}))?
)''',re.VERBOSE)
#TODO: create email regex.
#TODO: find matches in clipboard text.
#TODO: copy results to the clipboard.
# create email regex.
emailRegex = re.compile (r'''(
[a-zA-Z0-9._%+-]+
@
[a-zA-Z0-9.-]+
(\.[a-zA-Z]{2,4})
)''',re.VERBOSE )
text = str(pyperclip.paste())
matches = []
for group in phoneRegex.findall(text):
phonenum = '-'.join([groups[1], groups[3], groups[5]])
if groups[8] != '':
phonenum += 'x' + groups[8]
matches.append(phonenum)
for groups in emailRegex.findall(text):
matches.append(groups[0])
#TODO: copy resuilts to the clipboard.
if len(matches) > 0:
pyperclip.copy('\n'.join(matches))
print('copy to clipboard:')
print('\n'.join(matches))
else:
print('no phone number or email addresses found.')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/70894.html
標籤:其他
下一篇:[求助]在打包的時候報錯了:building for production...Error processing
