Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 /usr/bin/python3
- # phoneandemail.py- Finds all phone numbers and email addresses on the clipboard.
- import pyperclip
- import re
- # regex for phonenumber
- phoneregex = re.compile(r'''(
- (\d{3}|\(\d{3}\))? #areacode
- (\s|-|\.)? #seperator
- (\d{3}) #first 3 digits
- (\s|-|\.)? #seperator
- (\d{4}) #last four digits
- (\s*(ext|x|ext.)\s*(\d{2,5}))? #extension
- )''', re.VERBOSE)
- # regex for email
- 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)
- # Find Matches in the Clipboard
- text = str(pyperclip.paste())
- matches = []
- for groups 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])
- # copy results to the clipboard
- if len(matches) > 0:
- pyperclip.copy('\n'.join(matches))
- print('Copied to clipboard')
- print('\n'.join(matches))
- else:
- print('No phone numbers or emails were found')
Advertisement
Add Comment
Please, Sign In to add comment