summaryrefslogtreecommitdiffstats
path: root/Doc/library/re.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-06 07:19:15 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-06 07:19:15 (GMT)
commit70992c3c83e2324677ad4fee73f372682f036c18 (patch)
tree7416624db55fa0bf6ce0ba94f0978cbbcab73737 /Doc/library/re.rst
parentd2bbe526c37e0f3810c4acb3cc3a5d0fcbcbeae7 (diff)
downloadcpython-70992c3c83e2324677ad4fee73f372682f036c18.zip
cpython-70992c3c83e2324677ad4fee73f372682f036c18.tar.gz
cpython-70992c3c83e2324677ad4fee73f372682f036c18.tar.bz2
Expand on re.split behavior with captured expressions.
Diffstat (limited to 'Doc/library/re.rst')
-rw-r--r--Doc/library/re.rst14
1 files changed, 13 insertions, 1 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 9f13d06..2ab1254 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -543,14 +543,26 @@ form.
>>> re.split('\W+', 'Words, words, words.', 1)
['Words', 'words, words.']
+ 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
+ the end of the string::
+
+ >>> re.split('(\W+)', '...words, words...')
+ ['', '...', 'words', ', ', 'words', '...', '']
+
+ That way, separator components are always found at the same relative
+ indices within the result list (e.g., if there's one capturing group
+ in the separator, the 0th, the 2nd and so forth).
+
Note that *split* will never split a string on an empty pattern match.
- For example ::
+ For example::
>>> re.split('x*', 'foo')
['foo']
>>> re.split("(?m)^$", "foo\n\nbar\n")
['foo\n\nbar\n']
+
.. function:: findall(pattern, string[, flags])
Return all non-overlapping matches of *pattern* in *string*, as a list of