Overview
| Artifact ID: | f74c071c3edf2e8b4dff168904eb4f1dce9249d3f9a55518e7291bee3ab1f7b6 |
|---|---|
| Ticket: | 2798939fffffffffffffffffffffffffffffffff
Non-greedy quantifiers revert to greedy when branched |
| User & Date: | dram on 2017-10-26 01:36:45 |
Changes
- assignee changed to: "aku"
- closer changed to: "nobody"
- comment changed to:
Non-greedy quantifiers revert to greedy when used in conjunction with branches (pipe character). The following branch-free expression matches each letter in the test string and therefore correctly returns 14 regexp -all .+? {this is a test} The following branched expression matches the entire string only once because the quantifier reverts to greedy and therefore incorrectly returns 1 regexp -all .+?|x {this is a test} This breaks a lot of complex regular expressions that require non-greedy quantifiers and branches. - icomment:
Still true for 8.6.6 But this behaviour is stated clearly in re_syntax(n) as: An RE consisting of two or more branches connected by the | operator prefers longest match. BTW, PostgreSQL has same behaviour. (confirmed in PG 9.6.4)
- login: "dram"
- mimetype: "text/plain"
- severity changed to: "Minor"