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
You can switch on PCRE by using perl=T and some dark magic:
x <- '999|150|222|(123|145)|456|12,260|(10|10000)'
strsplit(x, '\\([^)]*\\)(*SKIP)(*F)|\\|', perl=T)
# [[1]]
# [1] "999" "150" "222" "(123|145)" "456"
# [6] "12,260" "(10|10000)"
The idea is to skip content in parentheses. Live demo
On the left side of the alternation operator we match anything in parentheses making the subpattern fail and force the regular expression engine to not retry the substring using backtracking control. The right side of the alternation operator matches | (outside of parentheses, what we want...)