@edzech asked how was it possible to split a string and keep the separators in it. His question was marked as duplicate, whereas the approach here is different than the "duplicate".
We want to split a string but by keeping the delimiters in it, we don't want them to be separated.
In brief, for <abc>d<e><f>ghi<j>
, we want:
['<abc>', 'd', '<e>', '<f>', 'ghi', '<j>']
instead of:
['<', 'abc', '>' 'd', '<', 'e', '>', '<', 'f', '>', 'ghi', '<', 'j', '>']
Using split
does not help since it will split according to the separator. We want to keep it attached to its content.