x <- "[abc], [def] abc,+def abc,def"reg <- "][^[]*\\[(*SKIP)(*F)|,(?!\\+)"strsplit(x, reg, perl=TRUE)gsub(reg, "@", x, perl=TRUE)
Standard input is empty
[[1]] [1] "[abc], [def] abc,+def abc" "def" [1] "[abc], [def] abc,+def abc@def"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!