(experimental) "finditer" method/function. this works pretty much

like findall, but returns an iterator (which returns match objects)
instead of a list of strings/tuples.
This commit is contained in:
Fredrik Lundh 2001-10-24 22:16:30 +00:00
parent 9242a4af17
commit 703ce8122c
2 changed files with 38 additions and 0 deletions

View file

@ -93,6 +93,7 @@ This module also defines an exception 'error'.
"""
import sys
import sre_compile
import sre_parse
@ -164,6 +165,15 @@ def findall(pattern, string):
Empty matches are included in the result."""
return _compile(pattern, 0).findall(string)
if sys.hexversion >= 0x02020000:
def finditer(pattern, string):
"""Return an iterator over all non-overlapping matches in
the string. For each match, the iterator returns a match
object.
Empty matches are included in the result."""
return _compile(pattern, 0).finditer(string)
def compile(pattern, flags=0):
"Compile a regular expression pattern, returning a pattern object."
return _compile(pattern, flags)