Reputation: 5951
I have the following:
s <- "abc, xyz, poi (cv, r2, 44, rghj), wer"
How can I split it so the end result is:
c("abc", "xyz", "poi (cv, r2, 44, rghj)", "wer")
Basically, strsplit
the string at every comma, but outside the parentheses.
Upvotes: 3
Views: 118
Reputation: 886948
Try
strsplit(s, "\\([^)]+\\)(*SKIP)(*FAIL)|, ", perl = TRUE)[[1]]
#[1] "abc" "xyz"
#[3] "poi (cv, r2, 44, rghj)" "wer"
Upvotes: 5