Tcl Source Code

View Ticket
Login
Ticket UUID: 6585b21ca8fa6f3678d442b97241fdd43dba2ec0
Title: Non-greedy match fails in combination with backreference
Type: Bug Version: 8.5.8
Submitter: anonymous Created on: 2013-07-18 23:03:22
Subsystem: 43. Regexp Assigned To: dgp
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2013-07-26 13:25:19
Resolution: Fixed Closed By: dgp
    Closed on: 2013-07-26 13:25:19
Description:
This regexp test fails, though it should succeed:

% regexp {(\w).*?\1} {Programmer}
0

If you remove the '?', it does succeed, showing that the problem is restricted to non-greedy mode.

This problem was initially reported to the Postgres project:
http://www.postgresql.org/message-id/CAM2+6=U8CdfM-qL55XHt+7hVzDRBnZwrHiVZRX2shGZ4OMuMSQ@mail.gmail.com

As per the discussion there, it seems that this is a bug in cfindloop(), and that the fix is that the /* no point in trying again */ code block is wrong and should be replaced by a simple "break;", allowing the intermediate loop to continue iterating with the next possible "begin" value.  I further suggested refactoring to merge that test into the subsequent statements that adjust estart/estop, but that's cosmetic, not essential to the fix.
User Comments: dgp added on 2013-07-26 13:25:19:
Fixed for 8.5.15 and 8.6.1.