SHARE
TWEET

Untitled

a guest Sep 17th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pyperclip, re
  2.  
  3. PHONE_REGEX = re.compile(r'''(
  4.     (\d{3}|\(\d{3}\))? # area code
  5.     (\s|-|\.)? # separator
  6.     (\d{3}) # first 3 digits
  7.     (\s|-|\.) # separator
  8.     (\d{4}) # last 4 digits
  9.     (\s*(ext|x|ext.)\s*(\d{2,5}))? # extension
  10.     )''', re.VERBOSE)
  11.  
  12. EMAIL_REGEX = re.compile(r'''(
  13.     [a-zA-Z0-9._%+-]+ # username
  14.     @ # @ symbol
  15.     [a-zA-Z0-9.-]+ # domain name
  16.     (\.[a-zA-Z]{2,4}) # dot-something
  17.     )''', re.VERBOSE)
  18.  
  19. def findPhoneMatches(text):
  20.     matches = []
  21.     for groups in PHONE_REGEX.findall(text):
  22.         phoneNum = '-'.join([groups[1], groups[3], groups[5]])
  23.         if groups[8] != '':
  24.             phoneNum += ' x' + groups[8]
  25.         matches.append(phoneNum)
  26.     return matches
  27.  
  28. def findEmailMatches(text):
  29.     matches = []
  30.     for groups in EMAIL_REGEX.findall(text):
  31.         matches.append(groups[0])
  32.     return matches
  33.  
  34.  
  35. text = str(pyperclip.paste())
  36. matches = findPhoneMatches(text) + findEmailMatches(text)
  37. if len(matches) > 0:
  38.     pyperclip.copy('\n'.join(matches))
  39.     print('Copied to clipboard:')
  40.     print('\n'.join(matches))
  41. else:
  42.     print('No phone numbers or email addresses found.')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top