Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kodos & "cannot refer to open group"

I want to only match 1010 or 0101 but nor 1111 nor 0000. I use the following regex :

\b((1|0)(?!\2))+

It works well in Kodos but I also want the matched sequence thanks to group(). I've tried :

\b(((1|0)(?!\2))+)

but "cannot refer to open group*" is displayed in Kodos and I don't understand why it doesn't work.

Please can you help me ?

Edit: The appropriate regex is (\b(((1|0)(?!\3))+).

like image 957
lilawood Avatar asked Jan 17 '23 02:01

lilawood


1 Answers

I believe the problem is that you have three separate groups in your second code line. They are numbered based on the ordering of the opening parens.

Group 1: ((1|0)(?!\2))+
Group 2: (1|0)(?!\2)
Group 3: 1|0

As you can see, group 2 contains a reference to itself, but it is still open while being parsed.

like image 104
VolatileRig Avatar answered Jan 18 '23 23:01

VolatileRig