I have a task for regexp to recognize 'right' codes:
010101
0101010
1111111
000000
This is example of 'not right' codes:
0110
001
11101
01
I wrote regexp:
^(?:([01])(?!\1))+$|^([01])\2*$
It works.. but I don't understand why :) I can't understand this part:
(?:([01])(?!\1))+
If this ([01])
is '1-st capturing group', then this (?!\1)
is not what we get in first capturing in 1-st capturing group
. But why it doesn't recognize this(it's right behavior, but why?):
012
? I mean, 2
is not 0
, that's what I expect from (?!\1)