summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFredrik Lundh <fredrik@pythonware.com>2001-10-24 22:16:30 (GMT)
committerFredrik Lundh <fredrik@pythonware.com>2001-10-24 22:16:30 (GMT)
commit703ce8122cadd68a4260318f44725398fc3a383c (patch)
treef93ce1a12ee954429a3d4dc3e1613f32ce726c72 /Lib
parent9242a4af177c4c62dfacdf633eb1bbdeba273b3c (diff)
downloadcpython-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.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/sre.py b/Lib/sre.py
index e7517f5..88b4fab 100644
--- a/Lib/sre.py
+++ b/Lib/sre.py
@@ -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)