我有以下内容:
s <- "abc, xyz, poi (cv, r2, 44, rghj), wer"
如何拆分它以便最终结果是:
c("abc", "xyz", "poi (cv, r2, 44, rghj)", "wer")
基本上,strsplit
每个逗号处的字符串,但在括号外。
答案 0 :(得分:5)
尝试
strsplit(s, "\\([^)]+\\)(*SKIP)(*FAIL)|, ", perl = TRUE)[[1]]
#[1] "abc" "xyz"
#[3] "poi (cv, r2, 44, rghj)" "wer"