Artifacts Associated With Ticket 524b35
Ticket change [98310803f7] (rid 171528) by tgl on 2019-05-12 18:45:58:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- 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 - foundin initialized to: "8.6.8"
- is_private initialized to: "0"
- login: "tgl"
- priority initialized to: "5 Medium"
- private_contact initialized to: "26864b65f1c6ce8bda86f87ed9c554e19ac0390d"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "tgl"
- subsystem initialized to: "43. Regexp"
- title initialized to:
can't force regex subexpression greediness as stated by man page
- type initialized to: "Bug"
Ticket change [08e0393ac0] (rid 171531) by jan.nijtmans on 2019-05-12 20:31:56:
- icomment:
Proposed fix committed in bug-524b35a8b5 branch. No test-case yet.
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [c08fbbcf6d] (rid 257494) by serhiy.storchaka on 2026-10-10 18:18:30:
- foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- 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. - login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
Ticket change [fdda65c176] (rid 261371) by oehhar on 2026-11-10 16:40:59:
- icomment:
Jan, is there any additional action? Serhiy proposes to also merge the doc fix in [fe4fca32d]. Thanks for all, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment: