I'd like to split an arbitrary string such as
x <- "(((K05708+K05709+K05710+K00529) K05711),K05712),K05713 K05714 K02554"
# [1] "(((K05708+K05709+K05710+K00529) K05711),K05712),K05713 K05714 K02554"
at delimiter(s) (here a space and a comma) except when they are within parentheses, and also keep the delimiters as part of the output
[[1]]
[1] "(((K05708+K05709+K05710 K00529) K05711),K05712)"
[2] ",K05713" " K05714"
[4] " K02554"
This example is copied almost directly from IgnacioF's (https://stackoverflow.com/users/5935889/ignaciof) post Split string by space except what's inside parentheses, as the example is a mere extension to it, and in knowing hands, solution could be too.
In the case of single delimiter, I could paste it into the output vector elements, but with multiple simultaneous delimiters, their identities are lost at splitting, so AFAIK this wouldn't work.
I have tried to find solution that keeps the delimiters using lookahead and other modifications to the solution to the original post, but in vain mostly because my lack of understanding its solution.