diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2001-10-24 22:16:30 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2001-10-24 22:16:30 (GMT) |
commit | 703ce8122cadd68a4260318f44725398fc3a383c (patch) | |
tree | f93ce1a12ee954429a3d4dc3e1613f32ce726c72 /Lib | |
parent | 9242a4af177c4c62dfacdf633eb1bbdeba273b3c (diff) | |
download | cpython-703ce8122cadd68a4260318f44725398fc3a383c.zip cpython-703ce8122cadd68a4260318f44725398fc3a383c.tar.gz cpython-703ce8122cadd68a4260318f44725398fc3a383c.tar.bz2 |
(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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sre.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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) |