I have the following regex:
/(1+(?=0|$))|(0+(?=1|$))/
I use it on strings composed of only 0
and 1
characters to split the string in groups of 0
s and 1
s. Here my regex matches groups of 1
s followed by a 0
or an end of line 1+(?=0|$)
or groups of 0
s followed by a 1
or an end of line 0+(?=1|$)
.
> '001100011101'.split(/(1+(?=0|$))|(0+(?=1|$))/).filter(c=>!!c)
[ '00', '11', '000', '111', '0', '1' ]
I am wondering if I could get the same result using something like /([01])+(?=[^$1]|$)/
to match 0
s or 1
s in a capture group (([01])
) followed by not what was in the capture group [^$1]
. This syntax clearly doesn't work and I can't find if something like this is possible or not.