'a|b||c|d'.split(re)
The results I want are
[ 'a', 'b||c', 'd' ]
That is, b and c are kept together because there are two vertical bars, not one.
I tried:
/(?:[^|])\|(?:[^|])/
That is, “match, but don’t capture, a non-vertical-bar before and after the separator”. Nope, doesn’t work at all.
(This is in Javascript, but I think a lot of RE libraries will work the same way.)
You would need lookaround (
/(?<!\|)\|(?!=\|)/), but lookbehind is not supported in JavaScript. Instead of splitting the string, try to match: