我试图和第29讲的人一样:正则表达式示例程序:来自udemy corse的电话和电子邮件。但我得到了错误,我不知道如何解决这个问题,视频中使用Windows的人也不知道。请帮忙。
#!/usr/bin/env python3.5
import re, pyperclip
# Create a regex for phone numbers
phoneRegex = re.compile(r"""
# 415-555-0000, 555-0000, (415) 555-0000, 555-000 ext 12345,
ext. 12345, X12345
(\d\d\d) | (\(\d\d\d\)))? # area code (optional)
(\s|-) # first separator
\d\d\d # first 3 digits
- # separator
\d\d\d\d # last 4 digits
(((ext(\.)?\s|x) # extansion word-part (optional)
(\d{2,5}))? # extansion number-part (optional)
""", re.VERBOSE)
# Create a regex for email addresses
emailRegex = re.compile(r"""
# some.+_thing@something.com
[a-zA-Z0-9_.+]+ # name part
@ # @ symbol
[a-zA-Z0-9_.+]+ # domain name part
""", re.VERBOSE)
# Get the text off the clipboard
text = pyperclip.paste()
# Extract the email/phone from this text
extractedPhone = phoneRegex.findall(text)
extractedEmail = emailRegex.findall(text)
print(extractedPhone)
print(extractedEmail)
我得到了这个错误:
Traceback (most recent call last):
File "/Users/TheBestOrNothing/Documents/MyPythonScripts/Firstpythonprogram.py", line 15, in <module>
""", re.VERBOSE)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/re.py", line 224, in compile
return _compile(pattern, flags)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/re.py", line 293, in _compile
p = sre_compile.compile(pattern, flags)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_compile.py", line 536, in compile
p = sre_parse.parse(p, flags)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_parse.py", line 834, in parse
raise source.error("unbalanced parenthesis")
sre_constants.error: unbalanced parenthesis at position 104 (line 3, column 24)
谢谢!!!