I have a string in python that I want to split in a very particular manner. I want to split it into a list containing each separate word, except for the case when a group of words are bordered by a particular character. For example, the following strings would be split as such.
'Jimmy threw his ball through the window.'
becomes
['Jimmy', 'threw', 'his', 'ball', 'through', 'the', 'window.']
However, with a border character I'd want
'Jimmy |threw his ball| through the window.'
to become
['Jimmy', 'threw his ball', 'through', 'the', 'window.']
As an additional component I need -
which may appear outside the grouping phrase to appear inside it after splitting up i.e.,
'Jimmy |threw his| ball -|through the| window.'
would become
['Jimmy', 'threw his', 'ball', '-through the', 'window.']
I cannot find a simple, pythonic way to do this without a lot of complicated for loops and if statements. Is there a simple way to handle something like this?