Kodos & “cannot refer to open group”

女生的网名这么多〃 提交于 2019-12-10 15:17:51

问题


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))+).


回答1:


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.



来源:https://stackoverflow.com/questions/11511083/kodos-cannot-refer-to-open-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!