import re
s_nums = 'one1two22three333four'
print(re.split('d+', s_nums))
# ['one', 'two', 'three', 'four']
from re import split
# 'W+' denotes Non-Alphanumeric Characters or group of characters Upon finding ',' or whitespace ' ', the split(), splits the string from that point
print(split('W+', 'Words, words , Words'))
print(split('W+', "Word's words Words"))
# Here ':', ' ' ,',' are not AlphaNumeric thus, the point where splitting occurs
print(split('W+', 'On 5th Jan 1999, at 11:02 AM'))
# 'd+' denotes Numeric Characters or group of characters Splitting occurs at '5', '1999','11', '02' only
print(split('d+', 'On 5th Jan 1999, at 11:02 AM'))
import re
# Splitting will occurs only once, at '05', returned list will have length 2
print(re.split('d+', 'On 05th Jan 1999, at 11:02 AM', 1))
# 'Boy' and 'boy' will be treated same when flags = re.IGNORECASE
print(re.split('[a-f]+', 'Aey, Boy oh boy, come here', flags=re.IGNORECASE))
print(re.split('[a-f]+', 'Aey, Boy oh boy, come here'))
re.split(pattern, string, maxsplit=0, flags=0)
import re
text = "python is, an easy;language; to, learn."
print(re.split("[;,] ", text))
import re
text = "python is, an easy;language; to, learn."
separators = "; ", ", "
def custom_split(sepr_list, str_to_split):
# create regular expression dynamically
regular_exp = '|'.join(map(re.escape, sepr_list))
return re.split(regular_exp, str_to_split)
print(custom_split(separators, text))