returning all matching groups with

Chris Rebert clp2 at
Thu Feb 3 21:42:55 CET 2011

On Thu, Feb 3, 2011 at 12:32 PM,
<mhearne808 at> wrote:
> Here's a scenario:
> import re
> m ='e','fredbarneybettywilma')
> Now, here's a stupid question:
> why doesn't m.groups() return ('e','e','e').

Straight from the docs ( ), emphasis mine:, string[, flags])
"Scan through string looking for **a** location where the regular
expression pattern produces **a** match [...]"

Hence, it stops looking after the very first match.

> I'm trying to figure out how to match ALL of the instances of a
> pattern in one call - the group() and groups() return subgroups... how
> do I get my search to get me all of the matching subgroups?

I think you want re.finditer() or re.findall().


More information about the Python-list mailing list