|
| 1 | +import pyperclip # Clipboard module |
| 2 | +import re # Regular expression module |
| 3 | + |
| 4 | +# Get the text from the clipboard |
| 5 | +text = str(pyperclip.paste()) |
| 6 | + |
| 7 | +# Empty list to store matches |
| 8 | +matches = [] |
| 9 | + |
| 10 | + |
| 11 | +def PhoneNumCheck(): |
| 12 | + # Regular expression for matching phone numbers |
| 13 | + PhnNumregex = re.compile( |
| 14 | + r""" |
| 15 | + (\(?(\+?\d{1,3})\)? # area code |
| 16 | + [\s_.-]?) # separator or space |
| 17 | + (\d{3}) # first three digits |
| 18 | + [\s_.-]? # separator or space |
| 19 | + (\d{3}) # second three digits |
| 20 | + [\s_.-]? # separator or space |
| 21 | + (\d{4,5}) # last four/five digits |
| 22 | + """, |
| 23 | + re.VERBOSE, |
| 24 | + ) # VERBOSE is used to ignore whitespace and comments inside the regex string |
| 25 | + |
| 26 | + # Loop through the phone numbers found in the text |
| 27 | + for num in PhnNumregex.findall(text): |
| 28 | + if num[1] != "": |
| 29 | + PhoneNum = "(" + num[1] + ")" # Add area code in brackets |
| 30 | + else: |
| 31 | + PhoneNum = "" |
| 32 | + PhoneNum += "-".join([num[2], num[3], num[4]]) # Join the digits with dashes |
| 33 | + matches.append(PhoneNum) |
| 34 | + |
| 35 | + |
| 36 | +def EmailCheck(): |
| 37 | + # Regular expression for matching email addresses |
| 38 | + emailCheck = re.compile( |
| 39 | + r""" |
| 40 | + ([a-zA-Z0-9._%-]+ # username |
| 41 | + @ # @ character |
| 42 | + [a-zA-Z0-9_-]+ # domain name |
| 43 | + \. # .(dot) |
| 44 | + [a-zA-Z]{2,3} # domain type |
| 45 | + (\.[a-zA-Z]{2,3})?) # second domain type like co.in |
| 46 | + """, |
| 47 | + re.VERBOSE, |
| 48 | + ) |
| 49 | + |
| 50 | + # Loop through the email addresses found in the text |
| 51 | + for emails in emailCheck.findall(text): |
| 52 | + matches.append(emails[0]) |
| 53 | + |
| 54 | + |
| 55 | +# Print the output from matches list |
| 56 | +def PrintMatches(): |
| 57 | + if len(matches) > 0: |
| 58 | + print("Found matches: " + str(len(matches))) |
| 59 | + for i in range(0, len(matches)): |
| 60 | + print(matches[i]) |
| 61 | + else: |
| 62 | + print("***No Phone Number or Email Address found.***") |
| 63 | + |
| 64 | + |
| 65 | +def main(): |
| 66 | + # Call functions to check for phone numbers and email addresses |
| 67 | + PhoneNumCheck() |
| 68 | + EmailCheck() |
| 69 | + |
| 70 | + # Print the matches |
| 71 | + PrintMatches() |
| 72 | + |
| 73 | + |
| 74 | +if __name__ == "__main__": |
| 75 | + main() |
0 commit comments