

If capture groups are used, then the matched text is also included in the result. When using re.split(), you need to be a bit careful should the regular expression pattern involve a capture group enclosed in parentheses. # followed by any amount of extra whitespace. Return a list of the words in the string, using sep as the delimiter string. > re.split(r'\s*', line) # split with delimiters comma, semicolon and space Splits the string at a given separator and returns a split list of substrings. In cases when you need a bit more flexibility, use the re.split() method: The split() method of string objects is really meant for very simple cases, and does not allow for multiple delimiters or account for possible whitespace around the delimiters. > str.split(',') # split string using delimiter comma Split string.split() methodĮasiest way to split a string using a delimiter is using string.split( delimiter ) function. The method does not alter the original string. Python example to split string into fields using the delimiters in the string. The split() method in Python breaks a string down into a list of substrings using a specified separator.
