I know how to split a string based on multiple separators using re as in this question: Split Strings with Multiple Delimiters?. But I'm wondering how to split a string using the order given in a list of delimiters where each split would only happen once.
multiple_sep_split("hello^goo^dbye:cat@dog", ['^',':','@'])
>>> ['hello', 'goo^dbye', 'cat', 'dog'] #(note the extra carat)
multiple_sep_split("my_cat:my_dog:my:bird_my_python",[':',':','_'])
>>> ['my_cat','my_dog','my:bird','my_python']
One approach could be to match not on the delimiters but on the text in between the delimiters and return those as groups but is there another way?
text_re = re.compile('(.+)^(.+):(.+)@(.+)') # get each group from here