mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
(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:
parent
9242a4af17
commit
703ce8122c
2 changed files with 38 additions and 0 deletions
10
Lib/sre.py
10
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue