[Python-checkins] r61269 - python/trunk/Doc/library/re.rst

georg.brandl python-checkins at python.org
Thu Mar 6 08:19:16 CET 2008


Author: georg.brandl
Date: Thu Mar  6 08:19:15 2008
New Revision: 61269

Modified:
   python/trunk/Doc/library/re.rst
Log:
Expand on re.split behavior with captured expressions.


Modified: python/trunk/Doc/library/re.rst
==============================================================================
--- python/trunk/Doc/library/re.rst	(original)
+++ python/trunk/Doc/library/re.rst	Thu Mar  6 08:19:15 2008
@@ -543,14 +543,26 @@
       >>> 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


More information about the Python-checkins mailing list