I am currently trying to split a string on the pipe delimiter:
999|150|222|(123|145)|456|12,260|(10|10000)
The catch is I don\'t want to s
This seems to work
x <- '999|150|222|(123|145)|456|12,260|(10|10000)'
m <- strsplit(x, '\\|(?=[^)]+(\\||$))', perl=T)
# [[1]]
# [1] "999" "150" "222" "(123|145)" "456" "12,260"
# [7] "(10|10000)"
Here we not just split on the |
but we also use a look ahead to make sure that there are no ")" marks before the next |
or the end of the string. Note that this method doesn't require or ensure the parenthesis are balanced and closed. We assume your input is well formatted.