#!/usr/bin/env python3

import re, pyperclip

# create a regex for phone number
PhoneRegex=re.compile(r'''
#415-555-0000, 555-0000, (415) 555-0000, 555-0000 ext 12345, ext 12345, x12345
(
 ((\d\d\d)|(\(\d\d\d\)))?   # area code
 (\s|-) #first separator
 \d\d\d #first 3 digitss
 -      #separator
 \d\d\d\d # last 4 digits
 (((ext(\.)?\s)|x) # extension word part
  (\d{2,5}))?   # extension number
)

''',re.VERBOSE)

#TODO: create a regex for email address

EmailRegex =re.compile(r'''
#something.+something@something.com
 [a-zA-Z0-9_.+]+  #name part
 @   # @symbol part
[a-zA-Z0-9_.+]+    # domain part

''',re.VERBOSE)
#Yukie's version : (\w+.)?\w+(.)?\w+@\w+(\.\w+.)?(\w+)?(\.\w+)?(\.\w+)?(\.\w+)?
#TODO: get the text off the clipboard

text=pyperclip.paste()
#TODO: Extract the email/phone from the text
extractedPhone=PhoneRegex.findall(text)
#TODO: copy the extract email/phone to the clipboard
extractedEmail=EmailRegex.findall(text)

allPhoneNumbers=[]
for phonenumber in extractedPhone:
    allPhoneNumbers.append(phonenumber[0])
print(allPhoneNumbers)
#print(extractedPhone)
#'\n'.join(allPhoneNumbers)
#'\n'.join(extractedEmail)

results='\n'.join(allPhoneNumbers)+'\n'+'\n'.join(extractedEmail)
pyperclip.copy(results)

