On Tue, Jun 29, 2021 at 11:51:13AM +0300, Egor Ignatov wrote: > Well, then I have a few questions about matching and capturing > groups. > > 1. "ab" -> "^(a*)*(.)" > So, from your test case I can assume that: > regs[0] = (0, 2] > regs[1] = (0, 1] > regs[2] = (1, 2] > > But if we add backref at the end: > 2. "ab" -> "^(a*)*(.)\1" > check_matching matches the whole string "ab", > this means that the first group accepted 'a' but in fact is empty, > otherwise it could not match backref later on. > What is the correct match here? Is check_matching wrong and > should match only "a" in the 2nd group (as it would be with > "^(a*)(.)\1")? or should set_regs check for this and shrink the > match?
My test-regex.c entry for a similar but a bit simplified case was: /* Test for ** match with backreferences. */ { "^(a*)*\\1", "a", REG_EXTENDED, 2, { { 0, 0 }, { 0, 0 } } } I suppose the corresponding entry for your example would be { "^(a*)*(.)\1", "ab", REG_EXTENDED, 3, { { 0, 1 }, { 0, 0 }, { 0, 1 } } } > Next, > 3. "aaba" -> "^(a*)*(.)\1" > Again check_matching matches "aaba", then the first group > is "a", and were the 2nd 'a' goes? I suppose the corresponding test-regex.c entry for this case would be { "^(a*)*(.)\1", "aaba", REG_EXTENDED, 3, { { 0, 4 }, { 0, 1 }, { 2, 3 } } } -- ldv