Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Non-greedy match fails in combination with backreference

Closed / Fixed6585b21ca8fa6f3678d442b97241fdd43dba2ec0Created 13 years agoUpdated 13 years ago
Descriptionplain2013-07-18 23:03:22
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.
Referenced by3
  • f60cd72d52New ticket [a6029ee505] regexp hangs with backreferences when a possible empty match fails. ticket2026-10-10 18:47:21
  • bff43cd4c3[6585b21ca8] [regexp {(\w).*?\1} abb] failed to match. Thanks to Tom Lane for passing on the discovery in Postgres. check-in2013-07-26 13:24:19
  • 2425a69341[6585b21ca8] [regexp {(\w).*?\1} abb] failed to match. Thanks to Tom Lane for passing on the discovery in Postgres. check-in2013-07-26 13:21:30
dgpplain2013-07-26 13:25:19
Fixed for 8.5.15 and 8.6.1.
Log in (anonymous is fine) to add a comment.