谁能解释为什么 print match.group() 只在第一次在下面的 for 循环中调用时返回结果匹配?我希望它每次调用时都会打印匹配项。我在阅读 Python Docs 中的本节时遇到了这个例子:Regex HOWTO
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> p = re.compile('\d+')
>>> iterator = p.finditer('12 drummers, 11 pipers, 10 dancers')
>>> iterator
<callable-iterator object at 0x107deabd0>
>>> for match in iterator:
... print match.group()
...
12
11
10
>>> for match in iterator:
... print match.group()
...
>>>