I am new to python and am currently learning regex
, I tried the following code and some error occurred, can somebody please advised pleased.
#! python3
import re, pyperclip
phoneRegex = re.compile(r'''
((\d\d\d) | (\(\d\d\d\)))?
\s|-
\d\d\d
-
\d\d\d\d
((ext(\.)?\s)|x)
(\d{2,5}))?
''', re.VERBOSE)
emailRegex = re.compile(r'''
[a-zA-Z0-9_.+]+
@
[a-zA-Z0-9_.+]+
''',re.VERBOSE)
text = pyperclip.paste()
extractedPhone = phoneRegex.findall(text)
extractedemail = emailRegex.findall(text)
print(extractedphone)
print (extractedemail)
Output:
Traceback (most recent call last):
File "C:/Users/Bane/Desktop/RegexProject.py", line 14, in <module>
''', re.VERBOSE)
File "C:\Users\Bane\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 234, in compile
return _compile(pattern, flags)
File "C:\Users\Bane\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 286, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\Bane\AppData\Local\Programs\Python\Python37-32\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\Bane\AppData\Local\Programs\Python\Python37-32\lib\sre_parse.py", line 944, in parse
raise source.error("unbalanced parenthesis")
re.error: unbalanced parenthesis at position 80 (line 9, column 10)
Document that I copied:
President Dr. Barbara Jones x107 870-864-7190 brjones@southark.edu Executive Assistant Ms. Susan Jordan x107 870-864-7190 sjordan@southark.edu Vice President for Finance and Dr. Belinda Aaron x147 870-864-7122 baaron@southark.edu