Consider the following code in R:
x <- "A, B (C, D, E), F, G [H, I, J], K (L (M, N), O), P (Q (R, S (T, U)))"
strsplit(x, split = "some regex here")
I would like this to return something resembling a list containing the character vector
"A"
"B (C, D, E)"
"F"
"G [H, I, J]"
"K (L (M, N), O)"
"P (Q (R, S (T, U)))"
EDIT: The proposed alternative questions do not answer my question, since nested parentheses and brackets are allowed, and it is possible for n-level nesting to occur (beyond 2).