Thesplit () function splits a string into a list of strings based on occurrences of the regular expression pattern. The string portions that don't match the pattern ate returned as a list of strings. If flags ate require d with the pattern, a regular expression objec t, obtained with compile ( ), must be used in place of the pattern string, or the ( ?iLmsx) sequences (which will be explained later) must be used within the expression. (TPr compiled regular expfeslion's split() method will aclideve the some resuhg )
split() has the following aptuments:
• patter n— the pattern, as a string, to search for
• maxsplit — the maximum number of splits to sake (the default is 0) It returns a list of strings.
from re import *
alist = split(":","OS=Linux:Browser=Netscape:WM=Afterstep")
The output is
Was this article helpful?