summaryrefslogtreecommitdiffstats
path: root/Lib/re.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-03-02 05:13:57 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2009-03-02 05:13:57 (GMT)
commitae91d0907d5e966eeadce1dc2a77680171bc182f (patch)
treed45bd9accec936428bb538a676688a4eed9ff999 /Lib/re.py
parent0261e5d0b65c6a935f88f59629ea658296cb3d8a (diff)
downloadcpython-ae91d0907d5e966eeadce1dc2a77680171bc182f.zip
cpython-ae91d0907d5e966eeadce1dc2a77680171bc182f.tar.gz
cpython-ae91d0907d5e966eeadce1dc2a77680171bc182f.tar.bz2
Adds an optional flags argument to re.split, re.sub and re.subn to be
consistent with the other re module functions.
Diffstat (limited to 'Lib/re.py')
-rw-r--r--Lib/re.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/re.py b/Lib/re.py
index 2cf7132..955b6b5 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -141,16 +141,16 @@ def search(pattern, string, flags=0):
a match object, or None if no match was found."""
return _compile(pattern, flags).search(string)
-def sub(pattern, repl, string, count=0):
+def sub(pattern, repl, string, count=0, flags=0):
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used."""
- return _compile(pattern, 0).sub(repl, string, count)
+ return _compile(pattern, flags).sub(repl, string, count)
-def subn(pattern, repl, string, count=0):
+def subn(pattern, repl, string, count=0, flags=0):
"""Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
@@ -159,12 +159,12 @@ def subn(pattern, repl, string, count=0):
callable; if a string, backslash escapes in it are processed.
If it is a callable, it's passed the match object and must
return a replacement string to be used."""
- return _compile(pattern, 0).subn(repl, string, count)
+ return _compile(pattern, flags).subn(repl, string, count)
-def split(pattern, string, maxsplit=0):
+def split(pattern, string, maxsplit=0, flags=0):
"""Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings."""
- return _compile(pattern, 0).split(string, maxsplit)
+ return _compile(pattern, flags).split(string, maxsplit)
def findall(pattern, string, flags=0):
"""Return a list of all non-overlapping matches in the string.