Is there any elegant way of splitting a text by a word and keep the word as well. Although there are some works around split with re package and pattern like (Python RE library String Split but keep the delimiters/separators as part of the next string), but none of them works for this scenario when the delimiter is repeated multiple times. For example:
s = "I want to split text here, and also keep here, and return all as list items"
Using partition:
s.partition("here")
>> ('I want to split text ', 'here', ', and also keep here, and return all as list items')
Using re.split():
re.split("here",s)
>> ['I want to split text ', ', and also keep ', ', and return all as list items']
The desired output should be something to the following list:
['I want to split text', 'here', ' , and also keep ', 'here', ' , and return all as list items']