]> granicus.if.org Git - python/commitdiff
Granted Noam Raphael's request for minor improvements to the re module and
authorRaymond Hettinger <python@rcn.com>
Fri, 24 Sep 2004 03:41:05 +0000 (03:41 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 24 Sep 2004 03:41:05 +0000 (03:41 +0000)
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().

Doc/lib/libre.tex
Lib/sre.py
Misc/NEWS

index 704db30a3fb876650bad43d59bdc90c185c94f78..0d9b7022d875d910c333672ef0193b2440b7a9c3 100644 (file)
@@ -424,8 +424,10 @@ re.compile("^a", re.M).search("ba", 1)   # fails; no preceding \n
 \subsection{Module Contents}
 \nodename{Contents of Module re}
 
-The module defines the following functions and constants, and an exception:
-
+The module defines several functions, constants, and an exception. Some of the
+functions are simplified versions of the full featured methods for compiled
+regular expressions.  Most non-trivial applications always use the compiled
+form.
 
 \begin{funcdesc}{compile}{pattern\optional{, flags}}
   Compile a regular expression pattern into a regular expression
@@ -552,21 +554,23 @@ ignored.
   the old \function{regsub.split()} and \function{regsub.splitx()}.
 \end{funcdesc}
 
-\begin{funcdesc}{findall}{pattern, string}
+\begin{funcdesc}{findall}{pattern, string\optional{, flags}}
   Return a list of all non-overlapping matches of \var{pattern} in
   \var{string}.  If one or more groups are present in the pattern,
   return a list of groups; this will be a list of tuples if the
   pattern has more than one group.  Empty matches are included in the
   result unless they touch the beginning of another match.
   \versionadded{1.5.2}
+  \versionchanged[Added the optional flags argument]{2.4}
 \end{funcdesc}
 
-\begin{funcdesc}{finditer}{pattern, string}
+\begin{funcdesc}{finditer}{pattern, string\optional{, flags}}
   Return an iterator over all non-overlapping matches for the RE
   \var{pattern} in \var{string}.  For each match, the iterator returns
   a match object.  Empty matches are included in the result unless they
   touch the beginning of another match.
   \versionadded{2.2}
+  \versionchanged[Added the optional flags argument]{2.4}
 \end{funcdesc}
 
 \begin{funcdesc}{sub}{pattern, repl, string\optional{, count}}
@@ -695,11 +699,13 @@ attributes:
 Identical to the \function{split()} function, using the compiled pattern.
 \end{methoddesc}
 
-\begin{methoddesc}[RegexObject]{findall}{string}
+\begin{methoddesc}[RegexObject]{findall}{string\optional{, pos\optional{,
+                                        endpos}}}
 Identical to the \function{findall()} function, using the compiled pattern.
 \end{methoddesc}
 
-\begin{methoddesc}[RegexObject]{finditer}{string}
+\begin{methoddesc}[RegexObject]{finditer}{string\optional{, pos\optional{,
+                                        endpos}}}
 Identical to the \function{finditer()} function, using the compiled pattern.
 \end{methoddesc}
 
index 8bf0fad321c5e0d68d84ec93b36d8b21b7ded77c..7969723e3f44e22a1fa0a635270af8292d6655f8 100644 (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."
index d3f4fe4b8b81da0c9a6bdde7f07753c568164600..edf5a0c6d09b022cb07eadb0369b91ec224b33e1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,11 @@ Extension modules
 Library
 -------
 
+- re's findall() and finditer() functions now take an optional flags argument
+  just like the compile(), search(), and match() functions.  Also, documented
+  the previously existing start and stop parameters for the findall() and
+  finditer() methods of regular expression objects.
+
 - rfc822 Messages now support iterating over the headers.
 
 - The (undocumented) tarfile.Tarfile.membernames has been removed;