PyDocs

Nav

Text Processing Services

split

re

function (source) Deprecated 3.13
  • split(pattern, string, maxsplit=0, flags=0)
Deprecated since 3.13. Passing maxsplit and flags as positional arguments is deprecated. In future Python versions they will be keyword-only parameters.
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.  If
capturing parentheses are used in pattern, then the text of all
groups in the pattern are also returned as part of the resulting
list.  If maxsplit is nonzero, at most maxsplit splits occur,
and the remainder of the string is returned as the final element
of the list.
Changed in 3.1, 3.7
  • 3.1: Added the optional flags argument.
  • 3.7: Added support of splitting on a pattern that could match an empty string.
1 Example
>>> re.split(r'\W+', 'Words, words, words.')
['Words', 'words', 'words', '']
>>> re.split(r'(\W+)', 'Words, words, words.')
['Words', ', ', 'words', ', ', 'words', '.', '']
>>> re.split(r'\W+', 'Words, words, words.', maxsplit=1)
['Words', 'words, words.']
>>> re.split('[a-f]+', '0a3B9', flags=re.IGNORECASE)
['0', '3', '9']
from the Python docs
See Also
No see-alsos for re/split
0 Notes
No notes for split