While writing code to search for USA phone number patterns which may or may not start with first 3 numbers like (415) or 415 (e.g full number like (415)-555-1234 ) encountered the error untermianted subpattern. Code :-
#! python3
import re, pyperclip
#TODO: Create a regex for phone numbers
phoneRegex = re.compile(r'''
((\d\d\d)|(\(\d\d\d\)))? # area code (optional) #this is for pattersn where 415 or (415) for which we puta ? at the end indicating appear 0 or 1 times
(\s|-) # first separator either - or a space
\d\d\d # first 3 digits
- #separator
\d\d\d\d # last 4 digits
(((ext(\.)?\s|x) #extension number part may be 2 till 5 characvters long
(\d{2,5}))? # as this entire number or extension part can be optional
''',re.VERBOSE)
#TODO: Create a regex for email addresses
#EMAIL part is working fine and tested on 10/08/22
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)
#TODO: Get text off the clipboard
text = pyperclip.paste()
#TODO: Extract the email/phone from this text
extractedPhone = phoneRegex.findall(text)
extractedEmail = emailRegex.findall(text)
#TODO: Copy the extracted email/phone to the clipboard
print(extractedPhone)
print(extractedEmail)
error thrown = re.error: missing ), unterminated subpattern at position 266 (line 7, column 1)