问题
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