Skip to content
Tcl Source Code History Of Ticket 2798939fffffffff
Login

History Of Ticket 2798939fffffffff

Artifacts Associated With Ticket 2798939fffffffff

  1. Ticket change [9955c485fa] (rid 110775) by bilgexa on 2009-05-30 21:15:37:

    1. assignee initialized to: "pvgoran"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized 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.
      
    4. foundin initialized to: "obsolete: 8.5.7"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "bilgexa"
    10. subsystem initialized to: "43. Regexp"
    11. title initialized to:
      Non-greedy quantifiers revert to greedy when branched
      
    12. type initialized to: "Bug"
  2. Ticket change [9d0f61643b] (rid 96247) by dkf on 2009-05-31 16:55:25:

    1. icomment:
      IIRC, the problem is that the "first" quantifier in the syntax tree is the alternation, which can't be made non-greedy. The fix is to use {1,1}? to force the whole RE to be non-greedy (a non-capturing paren is also needed, but that's pretty trivial).
      
      % regexp -all (?:.+?|x){1,1}? {this is a test}
      14
      
      Note that this is different from Perl/PCRE; they use a different model for greedy/non-greedy handling that does this in a way that is more as people intuitively expect (in return for being worse in other cases).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  3. Ticket change [4b312960d1] (rid 126656) by bilgexa on 2009-05-31 18:47:22:

    1. icomment:
      Surely you realise that this "fix" cannot possibly apply to complex alternations. The non-greedy quantifiers within the alternation group are all broken and this functionality can never be replaced by a single quantifier on the group as a whole.
      
      
    2. login: "bilgexa"
    3. mimetype: "text/plain"
    4. username: "bilgexa"
  4. Ticket change [f74c071c3e] (rid 157325) by dram on 2017-10-26 01:36:45:

    1. assignee changed to: "aku"
    2. closer changed to: "nobody"
    3. 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.
      
    4. 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)
      
    5. login: "dram"
    6. mimetype: "text/plain"
    7. severity changed to: "Minor"
  5. Ticket change [56d4066d01] (rid 157331) by dgp on 2017-10-26 02:10:01:

    1. icomment:
      Tcl and postgres make use of (forks of)
      the same regexp engine.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  6. Ticket change [65a2f7a6b9] (rid 257600) by serhiy.storchaka on 2026-10-11 10:49:37:

    1. icomment:
      Documented: an RE with a top-level <code>|</code> prefers the longest match.
      <code>(?:.+?|x){1,1}?</code> makes it prefer the shortest; <code>regexp -all</code>
      then returns 14. The docs are clarified in branch
      [/timeline?r=doc-re-syntax-preference|doc-re-syntax-preference]. Duplicate of [219219ffff].
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  7. Ticket change [8ec6abd2c0] (rid 257606) by serhiy.storchaka on 2026-10-11 10:52:40:

    1. login: "serhiy.storchaka"
    2. resolution changed to: "Duplicate"
    3. status changed to: "Closed"
  8. Ticket change [9c36b362b5] (rid 259884) by serhiy.storchaka on 2026-10-22 17:19:24:

    1. closedate changed to: "2461324.9532507984"
    2. closer changed to: "serhiy.storchaka"
    3. login: "serhiy.storchaka"