Skip to content

Instantly share code, notes, and snippets.

@eandrewgolden
Created April 17, 2017 20:59
Show Gist options
  • Save eandrewgolden/c0b05a9a26e6a7386d79177b1879502b to your computer and use it in GitHub Desktop.
Save eandrewgolden/c0b05a9a26e6a7386d79177b1879502b to your computer and use it in GitHub Desktop.
#! python3
import re, pyperclip
# Create a regex for phone numbers
phoneRegex = re.compile(r'''
# 415-555-000, 555-0000, (415) 555-0000, 555-000 ext 12345, ext. 12345, x12345
(
((\d\d\d) | (\(\d\d\d\)))? # area code optional
(\s|-) # first separator
\d\d\d # first 3 digits
- # seperator
\d\d\d\d # last 4 digits
(((ext(\.)?\s)|x) # extension word-part optional
(\d{2,5}))? # extension number-part optional
)
''', re.VERBOSE)
# Create a regex for email addresses
emailRegex = re.compile(r'''
# some.+_things@(\d{2,5}))?.com
[a-zA-Z0-9_.+]+ # name part
@ # @ symbol
[a-zA-Z0-9_.+]+ # domain name part
''', re.VERBOSE)
# Get the text off the clipboard
text = pyperclip.paste()
# TODO: Extract the email/phone from this text
extractedPhone = phoneRegex.findall(text)
extractedEmail = emailRegex.findall(text)
allPhoneNumbers = []
for phoneNumber in extractedPhone:
allPhoneNumbers.append(phoneNumber[0])
# TODO: Copy the extraced email/phone to the clipboard
results = '\n'.join(allPhoneNumbers) + '\n' + '\n'.join(extractedEmail)
pyperclip.copy(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment