returning all matching groups with re.search()
Chris Rebert
clp2 at rebertia.com
Thu Feb 3 15:42:55 EST 2011
More information about the Python-list mailing list
Thu Feb 3 15:42:55 EST 2011
- Previous message (by thread): returning all matching groups with re.search()
- Next message (by thread): returning all matching groups with re.search()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Feb 3, 2011 at 12:32 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com <mhearne808 at gmail.com> wrote: > Here's a scenario: > > import re > m = re.search('e','fredbarneybettywilma') > > Now, here's a stupid question: > why doesn't m.groups() return ('e','e','e'). Straight from the docs (http://docs.python.org/library/re.html ), emphasis mine: re.search(pattern, 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(). Cheers, Chris -- http://blog.rebertia.com
- Previous message (by thread): returning all matching groups with re.search()
- Next message (by thread): returning all matching groups with re.search()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list