diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2009-03-02 05:21:55 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2009-03-02 05:21:55 (GMT) |
commit | ccc5ae7ae13138eb3acf3a15e92983a49e53dd90 (patch) | |
tree | ec15b883a13aa8ee8cfcfdcf0e633e83ec236422 /Doc | |
parent | 4221c74cb00fa00ce8b4a6015c59a233246bf1e9 (diff) | |
download | cpython-ccc5ae7ae13138eb3acf3a15e92983a49e53dd90.zip cpython-ccc5ae7ae13138eb3acf3a15e92983a49e53dd90.tar.gz cpython-ccc5ae7ae13138eb3acf3a15e92983a49e53dd90.tar.bz2 |
Merged revisions 70090 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70090 | gregory.p.smith | 2009-03-01 21:13:57 -0800 (Sun, 01 Mar 2009) | 3 lines
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 'Doc')
-rw-r--r-- | Doc/library/re.rst | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 9399a49..ed50ddb 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -571,7 +571,7 @@ form. instead. -.. function:: split(pattern, string[, maxsplit=0]) +.. function:: split(pattern, string[, maxsplit=0, flags=0]) Split *string* by the occurrences of *pattern*. If capturing parentheses are used in *pattern*, then the text of all groups in the pattern are also returned @@ -585,6 +585,8 @@ form. ['Words', ', ', 'words', ', ', 'words', '.', ''] >>> re.split('\W+', 'Words, words, words.', 1) ['Words', 'words, words.'] + >>> re.split('[a-f]+', '0a3B9', flags=re.IGNORECASE) + ['0', '3', '9'] If there are capturing groups in the separator and it matches at the start of the string, the result will start with an empty string. The same holds for @@ -605,6 +607,9 @@ form. >>> re.split("(?m)^$", "foo\n\nbar\n") ['foo\n\nbar\n'] + .. versionchanged:: 2.7,3.1 + Added the optional flags argument. + .. function:: findall(pattern, string[, flags]) @@ -625,7 +630,7 @@ form. match. -.. function:: sub(pattern, repl, string[, count]) +.. function:: sub(pattern, repl, string[, count, flags]) Return the string obtained by replacing the leftmost non-overlapping occurrences of *pattern* in *string* by the replacement *repl*. If the pattern isn't found, @@ -650,6 +655,8 @@ form. ... else: return '-' >>> re.sub('-{1,2}', dashrepl, 'pro----gram-files') 'pro--gram files' + >>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE) + 'Baked Beans & Spam' The pattern may be a string or an RE object; if you need to specify regular expression flags, you must use a RE object, or use embedded modifiers in a @@ -670,12 +677,18 @@ form. character ``'0'``. The backreference ``\g<0>`` substitutes in the entire substring matched by the RE. + .. versionchanged:: 2.7,3.1 + Added the optional flags argument. + -.. function:: subn(pattern, repl, string[, count]) +.. function:: subn(pattern, repl, string[, count, flags]) Perform the same operation as :func:`sub`, but return a tuple ``(new_string, number_of_subs_made)``. + .. versionchanged:: 2.7,3.1 + Added the optional flags argument. + .. function:: escape(string) |