Is is possible to write a regex where I can somehow refer the "length of the first capture group" later in the same regex? What I am trying to achieve here is to capture continuous occurrences of 1
's that are followed by the exact number of continuous occurrences of 2
's.
I want something like
r"(1*)(2{length(\1)})" # where `length(\1)` should give me the length of capture group 1
Should Match
1122 # two 1's followed by two 2's
111222 # three 1's followed by three 2's
121122111222 # should match `12` and `1122` and `111222` separately
Should Not Match
122 # there are two 2's following one 1
112 # there are two 1's but only one 2
11222 # same as above but with different occurrences
11122 # same as above but with different occurrences