Skip to content
Tcl Source Code History Of Ticket 524b35
Login

History Of Ticket 524b35

Artifacts Associated With Ticket 524b35

  1. Ticket change [98310803f7] (rid 171528) by tgl on 2019-05-12 18:45:58:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      The re_syntax man page states
      
      The quantifiers \fB{1,1}\fR and \fB{1,1}?\fR can be used to
      force longest and shortest preference, respectively, on a
      subexpression or a whole RE.
      
      However, this doesn't actually work reliably, for example
      
      % regexp -inline {^(l*)(.*)(f*)$} {llmmmfff}
      llmmmfff ll mmmfff {}
      % regexp -inline {^(l*){1,1}?(.*)(f*)$} {llmmmfff}
      llmmmfff ll mmmfff {}
      
      The first result is fine, but the second result should have been
      
      llmmmfff {} llmmmfff {}
      
      that is, the (l*) should have been forced to be non-greedy.
      
      I tracked this down to an over-optimistic optimization in parseqatom():
      it throws away a {1,1} quantifier without regard to whether it's trying to impose
      a different greediness than the atom would have natively.
      
      This seems to be sufficient to fix it:
      
      @@ -1155,7 +1155,10 @@ parseqatom(struct vars *v,
       		/* rest of branch can be strung starting from atom->end */
       		s2 = atom->end;
       	}
      -	else if (m == 1 && n == 1)
      +	else if (m == 1 && n == 1 &&
      +			 (qprefer == 0 ||
      +			  (atom->flags & (LONGER | SHORTER | MIXED)) == 0 ||
      +			  qprefer == (atom->flags & (LONGER | SHORTER | MIXED))))
       	{
       		/* no/vacuous quantifier:  done */
       		EMPTYARC(s, atom->begin);	/* empty prefix */
      
      (That's from a draft Postgres patch, your formatting of the code is different)
      
      BTW, I think that the weasel wording in the NOTE in re_syntax.n immediately
      after the above-quoted bit is due to this bug.
      
      Background at
      https://www.postgresql.org/message-id/flat/20583.1557680147%40sss.pgh.pa.us
      
    5. foundin initialized to: "8.6.8"
    6. is_private initialized to: "0"
    7. login: "tgl"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "26864b65f1c6ce8bda86f87ed9c554e19ac0390d"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "tgl"
    14. subsystem initialized to: "43. Regexp"
    15. title initialized to:
      can't force regex subexpression greediness as stated by man page
      
    16. type initialized to: "Bug"
  2. Ticket change [08e0393ac0] (rid 171531) by jan.nijtmans on 2019-05-12 20:31:56:

    1. icomment:
      Proposed fix committed in bug-524b35a8b5 branch. No test-case yet.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  3. Ticket change [c08fbbcf6d] (rid 257494) by serhiy.storchaka on 2026-10-10 18:18:30:

    1. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
    2. icomment:
      Still the same in 8.6, 9.0 and 9.1: <tt>parseqatom()</tt> dropped every <tt>{1,1}</tt> as vacuous, so <tt>{1,1}?</tt> could not make a greedy atom non-greedy, and <tt>{1,1}</tt> could not make a non-greedy atom greedy (e.g. <tt>(.*?){1,1}(.*)</tt>), contrary to re_syntax.n.
      
      Proposed fix in branch [/timeline?r=regexp-1-1-quantifier-preference|regexp-1-1-quantifier-preference]: your patch, which keeps the quantifier when it asks for a different preference than the atom has. With it, the results agree with PostgreSQL on the example and on other <tt>{1,1}</tt> and <tt>{1}</tt> cases. Tests reg-25.4 to 25.9. Branch bug-524b35a8b5 had the same change without tests, based on core-8-5-branch.
      
    3. login: "serhiy.storchaka"
    4. mimetype: "text/x-fossil-wiki"
  4. Ticket change [fdda65c176] (rid 261371) by oehhar on 2026-11-10 16:40:59:

    1. icomment:
      Jan,
      is there any additional action?
      Serhiy proposes to also merge the doc fix in [fe4fca32d].
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"