Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mac OS X 10.10 Yosemite,python 3.5,关于详细错误_Python_Regex_Macos_Module_Copy Paste - Fatal编程技术网

Mac OS X 10.10 Yosemite,python 3.5,关于详细错误

Mac OS X 10.10 Yosemite,python 3.5,关于详细错误,python,regex,macos,module,copy-paste,Python,Regex,Macos,Module,Copy Paste,我试着像第29课:Regex示例程序:我的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-

我试着像第29课:Regex示例程序:我的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)
回溯(最近一次呼叫最后一次):
文件“/Users/TheBestOrNothing/Documents/MyPythonScripts/Firstpythonprogram.py”,第15行,在
“”,re.VERBOSE)
文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/re.py”,编译中的第224行
返回编译(模式、标志)
文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/re.py”,第293行,在编译中
p=sre_compile.compile(模式、标志)
compile中的文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_compile.py”,第536行
p=sre_parse.parse(p,标志)
parse中的文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_parse.py”,第834行
raise source.error(“不平衡括号”)
sre_constants.error:位置104处的不平衡括号(第3行,第24列)

谢谢!!!

看起来您的“区号”行中的右括号太多了。谢谢,伙计。您帮了我很多忙!我发现了一个问题。正如您所说,这是括号的问题,但有点不同。我在开始时在代码(\d\d\d)|(\d\d\d))?之前漏掉了括号,在这里漏掉了括号((ext(\)?\s\x)。更改后的代码开始工作。应该是这样((\d\d\d)|((\d\d\d))?和(((ext(\)?\s)| x)。再次感谢您的快速响应。