How to split a string based on a regular expression in Python

Splitting a string based on a regular expression splits the string into a list where every element of the list is the words or characters separated by the regular expression specified. For example, splitting the string “Apple, Orange, Grape” by a “,” results in the list [“Apple”, “Orange”, “Grape”].

Solution for How to split a string based on a regular expression in Python : You can use re.split() to split a string based on a regular expression Call re.split(pattern, string) to split string at every occurrence of a regular expression pattern.


how-to-split-a-string-based-on-a-regular-expression-in-python