Granted Noam Raphael's request for minor improvements to the re module and

its documentation.

* Documented that the compiled re methods are supposed to be more full
  featured than their simpilified function counterparts.

* Documented the existing start and stop position arguments for the
  findall() and finditer() methods of compiled regular expression objects.

* Added an optional flags argument to the re.findall() and re.finditer()
  functions.  This aligns their API with that for re.search() and
  re.match().
This commit is contained in:
Raymond Hettinger 2004-09-24 03:41:05 +00:00
parent 9fa544cfa3
commit 596ba4d89e
3 changed files with 21 additions and 10 deletions

View file

@ -156,7 +156,7 @@ def split(pattern, string, maxsplit=0):
returning a list containing the resulting substrings."""
return _compile(pattern, 0).split(string, maxsplit)
def findall(pattern, string):
def findall(pattern, string, flags=0):
"""Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
@ -164,16 +164,16 @@ def findall(pattern, string):
has more than one group.
Empty matches are included in the result."""
return _compile(pattern, 0).findall(string)
return _compile(pattern, flags).findall(string)
if sys.hexversion >= 0x02020000:
__all__.append("finditer")
def finditer(pattern, string):
def finditer(pattern, string, flags=0):
"""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)
return _compile(pattern, flags).finditer(string)
def compile(pattern, flags=0):
"Compile a regular expression pattern, returning a pattern object."