擅长:python、mysql、java
<p>它似乎是一个python bug(在vim中工作得很好)。
问题的根源是(\s*…)+位。基本上,你不能做有意义的<code>(\s*)+</code>,因为你试图重复一些可以为空的东西。</p>
<pre><code>>>> re.compile(r"(\s*)+")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 180, in compile
return _compile(pattern, flags)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/re.py", line 233, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
</code></pre>
<p>但是<code>(\s*\1)</code>不应该为空,但是我们知道它只是因为我们知道在1中有什么。显然Python不会。。。真奇怪。</p>