Overview
| Artifact ID: | 98310803f7c4861ecb1eff727efb0c2259a60766bc19a8f24dca8dd9d097d96e |
|---|---|
| Ticket: | 524b35a8b5f9ec643fc323582217193d91247430
can't force regex subexpression greediness as stated by man page |
| User & Date: | tgl on 2019-05-12 18:45:58 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed 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 changed to: "8.6.8"
- is_private changed to: "0"
- login: "tgl"
- priority changed to: "5 Medium"
- private_contact changed to: "26864b65f1c6ce8bda86f87ed9c554e19ac0390d"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "tgl"
- subsystem changed to: "43. Regexp"
- title changed to:
can't force regex subexpression greediness as stated by man page
- type changed to: "Bug"