I am trying to split strings of a format
x <- "A(B)C"
where A, B and C could be empty strings or any sets of characters except for parentheses. The parentheses are always there - I want to keep them around the characters they enclose, so that the result would be:
"A" "(B)" "C"
So far my best try was:
strsplit(x, "(?<=\\))|(?=\\()", perl = TRUE)
[[1]]
[1] "A" "(" "B)" "C"
but that keeps the opening parenthesis separate. Any ideas?