Python RegEx split() Functions

This function splits the string at every occurrence of the sub-string and returns a list of strings which have been split.

Split string by the occurrences of a character or a pattern, upon finding that pattern, the remaining characters from the string are returned as part of the resulting list. 

Syntax:

import re
re.split(pattern, string, maxsplit=0, flags=0)

Example:

import re
str1 = "Welcome to Python Programming"
res = re.split("\s", str1)
print(res)

Output: ['Welcome', 'to', 'Python', 'Programming']

Tags