[Python-Dev] iterator support for SRE?
Fredrik Lundh
fredrik@pythonware.com
Wed, 24 Oct 2001 23:52:51 +0200
a common wish for SRE is a variant of findall that returns
all match objects, instead of the strings.
recently, I realized that the internal scanner type (originally
added to speed up Python versions of findall/sub/split) can
be wrapped in an iterator, allowing the user to loop over all
matches.
>>> import re
>>> p = re.compile(somepattern)
>>> for match in iter(p.scanner(somestring).search, None):
>>> print match.groups()
how about adding a "finditer" method, which takes care of
the low-level setup:
>>> for match in p.finditer(somestring):
>>> print match.groups()
or should we just make the scanner factory an official part
of the SRE interface?
</F>