擅长:python、mysql、java
<p>您的模式运行得很好,您只需将其与<code>finditer</code>一起使用即可执行全局研究并获得整个匹配:</p>
<pre><code>>>> for m in re.finditer(pattern, text):
... print 'whole match: %s' (m.group(0))
... print 'group "braced": %s' % (m.group('braced'))
... print 'group "named": %s\n' % (m.group('named'))
</code></pre>
<p>(<code>findall</code><em>(也执行全局研究)</em>的问题是,当模式中有捕获组时,结果只包含捕获组内容的列表,而不包含整个匹配结果。因此,根据stribizhev的建议,将所有内容都包含在一个捕获组中可以是一种使用<code>findall</code>的方法。你知道吗</p>