Advertisement
brandonmunda1

phoneandemail

Mar 10th, 2022
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  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. 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. matches = []
  23. for groups in phoneRegex.findall(text):
  24.     phoneNum = '-'.join([groups[1], groups[3], groups[5]])
  25.     if groups[8] != '':
  26.         phoneNum += ' x' + groups[8]
  27.     matches.append(phoneNum)
  28. for groups in email.Regex.findall(text):
  29.     matches.append(groups[0])
  30.  
  31. if len(matches) > 0:
  32.     pyperclip.copy('\n'.join(matches))
  33.     print('Copied to clipboard:')
  34.     print('\n'.join(matches))
  35. else:
  36.     print('No phone numbers or email addresses found.')
  37.  
  38. # TODO: Find matches in clipboard text.
  39.  
  40. # TODO: Copy results to the clipboard.
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement