I would like to split a string, with multiple delimiters, but keep the delimiters in the resulting list. I think this is a useful thing to do an an initial step of parsing any kind of formula, and I suspect there is a nice Python solution.
Someone asked a similar question in Java here.
For example, a typical split looks like this:
>>> s='(twoplusthree)plusfour'
>>> s.split(f, 'plus')
['(two', 'three)', 'four']
But I'm looking for a nice way to add the plus back in (or retain it):
['(two', 'plus', 'three)', 'plus', 'four']
Ultimately I'd like to do this for each operator and bracket, so if there's a way to get
['(', 'two', 'plus', 'three', ')', 'plus', 'four']
all in one go, then all the better.