It looks like you can just split on &[^;]*;
regex. That is, the delimiter are strings that starts with &
, ends with ;
, and in between there can be anything but ;
.
If you can have multiple delimiters in a row, and you don't want the empty strings between them, just use (&[^;]*;)+
(or in general (
delim
)+
pattern).
If you can have delimiters in the beginning or front of the string, and you don't want them the empty strings caused by them, then just trim them away before you split.
Example
Here's a snippet to demonstrate the above ideas (see also on ideone.com):
var s = ""Hello <everybody> there""
print (s.split(/&[^;]*;/));
// ,Hello,,everybody,,there,
print (s.split(/(?:&[^;]*;)+/));
// ,Hello,everybody,there,
print (
s.replace(/^(?:&[^;]*;)+/, "")
.replace(/(?:&[^;]*;)+$/, "")
.split(/(?:&[^;]*;)+/)
);
// Hello,everybody,there