Skip to content
Tcl Source Code History Of Ticket 219219
Login

History Of Ticket 219219

Artifacts Associated With Ticket 219219

  1. Ticket change [a91be4badb] (rid 99101) by nobody on 2000-10-26 05:03:45:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 4001 Bug
      Version: 8.2.3
      SubmitDate: '2000-01-10'
      LastModified: '2000-01-27'
      Severity: MED
      Status: Assigned
      Submitter: techsupp
      ChangedBy: hobbs
      RelatedBugIDs: 2866
      OS: BSD
      OSVersion: NetBSD-1.4.1/i386
      FixedDate: '2000-10-25'
      ClosedDate: '2000-10-25'
      
      
      Name: hume smith
      
      ReproducibleScript:
      > tclsh
      % regexp {x.*?([a-z]+)} {1234x56789word101112} a b
      1
      % set a
      x56789w
      % set b
      w
      % set tcl_patchLevel
      8.2.3
      %
      
      ObservedBehavior:
      the + was matched in a nongreedy fashion; shouldn't it be greedy?
      
      DesiredBehavior:
      % set a
      x56789word
      % set b
      word
      %
      
      Patch:
      
      
      PatchFiles:
      
      
      
      
      Henry Spencer has noted some problems with mixing greedy and
      non-greedy quantifiers in the new regexp code.  He's cc'ed on
      this, but in the meantime, the work-around is:
          regexp {x[^a-z]*([a-z]+)} {1234x56789word101112} a b 
      -- 01/10/2000 hobbs
      From HS:
      
      This is the same old problem:  people accustomed to Perl are not grasping
      the idea that the whole RE is greedy or non-greedy, but *not* some mixture
      of the two.  In this case, it is non-greedy since the first thing in it
      which cares is non-greedy.  The + is being as greedy as it can, within the
      constraints set by the behavior of the whole RE. 
      
      In short, the behavior, while surprising, is as documented.  It's not an
      outright bug; it may, however, be a misfeature.
       
      -- 01/10/2000 hobbs
      
    4. foundin initialized to: "final: 8.2.3"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "43. Regexp"
    10. title initialized to: "greedy vs. non-greedy confusion"
    11. type initialized to: "Bug"
  2. Ticket change [570ff4b441] (rid 94424) by dkf on 2000-11-10 17:48:16:

    1. icomment:
      Perhaps this requires a documentation change?  Well, either that or a behaviour change.  Would it be possible to have a flag to force greediness or non-greediness instead of guessing it from the first quantifier in the regular expression?  (With the default being greedy unless all the "top-level" quantifiers were non-greedy, maybe?)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  3. Ticket change [3db2a1b9c6] (rid 121130) by andreas_kupries on 2001-09-08 06:33:56:

    1. assignee changed to: "hobbs"
  4. Ticket change [4de07e62c4] (rid 127132) by nobody on 2001-11-20 05:45:44:

    1. icomment:
      Logged In: NO 
      
      I couldnt find anything to confirm this behavior in 'man 
      re_syntax(n)'.  Where has it been documented into 
      semi-legitimacy?
      
      Any correlation between familiarity with perl and noticing 
      this behavior is purely coincidental.  I mean, come on... 
      If greedyness is meant to be a 'whole expression' 
      behavior, why isnt it implemented as a switch, like with
      the '-nocase' option?   Calling it a misfeature is being 
      too kind, especially considering the amount of grief it 
      causes the people who are affected by it. ;')
      
      
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  5. Ticket change [5193fdd2d5] (rid 126156) by segeth on 2006-10-05 21:29:16:

    1. icomment:
      Logged In: YES 
      user_id=1613941
      
      The problem greedy mixing non-greedy still exists in tcl
      v8.4. . In my opinion mixing those two one's should be
      possible, actually i have to split the RE ... one for
      non-greedy and one for greedy. It isn't explained in the
      manual re_syntax, that you can't create a mixture of greedy
      and non-greedy quantifiers.
      
      I like to know is it a documentation bug or a bug in the tcl
      interpreter?
      
      
    2. login: "segeth"
    3. mimetype: "text/plain"
    4. username: "segeth"
  6. Ticket change [a14949605b] (rid 157326) by dram on 2017-10-26 01:40:45:

    1. assignee changed to: "aku"
    2. closer changed to: "nobody"
    3. comment changed to:
      OriginalBugID: 4001 Bug
      Version: 8.2.3
      SubmitDate: '2000-01-10'
      LastModified: '2000-01-27'
      Severity: MED
      Status: Assigned
      Submitter: techsupp
      ChangedBy: hobbs
      RelatedBugIDs: 2866
      OS: BSD
      OSVersion: NetBSD-1.4.1/i386
      FixedDate: '2000-10-25'
      ClosedDate: '2000-10-25'
      
      
      Name: hume smith
      
      ReproducibleScript:
      > tclsh
      % regexp {x.*?([a-z]+)} {1234x56789word101112} a b
      1
      % set a
      x56789w
      % set b
      w
      % set tcl_patchLevel
      8.2.3
      %
      
      ObservedBehavior:
      the + was matched in a nongreedy fashion; shouldn't it be greedy?
      
      DesiredBehavior:
      % set a
      x56789word
      % set b
      word
      %
      
      Patch:
      
      
      PatchFiles:
      
      
      
      
      Henry Spencer has noted some problems with mixing greedy and
      non-greedy quantifiers in the new regexp code.  He's cc'ed on
      this, but in the meantime, the work-around is:
          regexp {x[^a-z]*([a-z]+)} {1234x56789word101112} a b 
      -- 01/10/2000 hobbs
      From HS:
      
      This is the same old problem:  people accustomed to Perl are not grasping
      the idea that the whole RE is greedy or non-greedy, but *not* some mixture
      of the two.  In this case, it is non-greedy since the first thing in it
      which cares is non-greedy.  The + is being as greedy as it can, within the
      constraints set by the behavior of the whole RE. 
      
      In short, the behavior, while surprising, is as documented.  It's not an
      outright bug; it may, however, be a misfeature.
       
      -- 01/10/2000 hobbs
      
    4. icomment:
      Also encoutered this problem recently, with a simpler case:
      
        % regexp -inline {(.+?), (.+)} "foo, bar"
        {foo, b} foo b
      
      But this is expected behaviour as stated by re_syntax(n), and PostgreSQL have a more throughly description[1].
      
      
      [1] https://www.postgresql.org/docs/10/static/functions-matching.html#functions-posix-regexp  (in 9.7.3.5. Regular Expression Matching Rules)
      
    5. login: "dram"
    6. mimetype: "text/plain"
    7. severity changed to: "Minor"
  7. Ticket change [31540dc69b] (rid 257602) by serhiy.storchaka on 2026-10-11 10:51:38:

    1. icomment:
      This is the documented rule: the first quantified atom, <code>.*?</code>, makes the
      whole match as short as possible, and <code><nowiki>[a-z]+</nowiki></code> is greedy only within it.
      PostgreSQL (same engine) gives the same result. Workarounds:
      <code><nowiki>(?:x.*?([a-z]+)){1,1}</nowiki></code> or <code><nowiki>x[^a-z]*([a-z]+)</nowiki></code>; both give
      <code>word</code>. The docs are clarified in branch
      [/timeline?r=doc-re-syntax-preference|doc-re-syntax-preference] (see [fe4fca32d9]).
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  8. Ticket change [fb8ee630fc] (rid 257604) by serhiy.storchaka on 2026-10-11 10:52:40:

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

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