iterator support for SRE?
Oct. 24, 2001
9:52 p.m.
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>
9136
Age (days ago)
9139
Last active (days ago)
5 comments
4 participants
participants (4)
-
barry@zope.com -
Fredrik Lundh -
Guido van Rossum -
Tim Peters