#! python3 # phoneAndEmail.py - Finds phone numbers and email addresses on the clipboard. # Site to test against: https://dese.ade.arkansas.gov/Offices/ar-comp-sci-initiative/statewide-computer-science-specialists import pyperclip, re # Create phone number regex with or without area code, but uses a '-' seperator. phoneRegex = re.compile(r''' EXPRESSION HERE ''', re.VERBOSE) # Create phone number regex with no seperators, with or without leading 1 before area code. phone2Regex = re.compile(r''' EXPRESSION HERE ''', re.VERBOSE) # Create email regex. emailRegex = re.compile(r''' EXPRESSION HERE ''', re.VERBOSE) # Find matches in clipboard text. 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 phone2Regex.findall(text): phoneNum = '-'.join([groups[2], groups[3], groups[4]]) 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 email addresses found.')