Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 26238b7f7530f7af939e7a49b7471b61a93bf68e
Ticket: 11250a236da29e6badf7755a1b67995defa5170f
unexpected non greedy matching behaviour
User & Date: anonymous on 2015-05-17 14:55:33
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    since there seems no suitable mailing list to ask and I presume it's a bug I'm reporting this here: non-greedy matching seems not to work as it should in certain contexts, specifically, matching seemingly becomes greedy if the respective atom is preceded by a pattern containing `+'  to indicate arbitrary (one or more) occurrence of chars from a range or class.
    
    example:
    
    # a string with four sub-patterns I want to capture (the latex-like constructs `\emph{xxx}'):
    
    set s "\emph{A} a \emph{B} b \emph{C} c \ital{D} d"
    
    # this one correctly finds all four of them, when specifying that the stuff before `{xxx}' consists of exactly 4 letters:
    
    regexp -all  {(\\[a-z]{4})\{(.*?)\}} $s dum; puts $dum; # ==> \ital{D}  <== (OK)
    
    # allowing "one or more" chars instead of "exactly 4" changes the match to "greedy", i.e. it reports a _single_ match of
    # everyting up to the last closing `}':
    
    regexp -all  {(\\[a-z]+)\{(.*?)\}} $s dum; puts $dum; # == > \emph{A} a \emph{B} b \emph{C} c \ital{D} <==(WRONG)
    
    # the same problem here:
    regexp -all  {(\\w+)\{(.*?)\}} $s dum; puts $dum; # == > \emph{A} a \emph{B} b \emph{C} c \ital{D} <==(WRONG)
    
    
    is this a bug or am I completely misunderstanding how non-greedy matching is supposed to work/be used?
    
    thanks 
    
    joerg
    
  5. foundin changed to: "8.6"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "87a8ab2e1e5150e17c388ae3d6a4369041a5c4fa"
  10. resolution changed to: "None"
  11. severity changed to: "Severe"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "43. Regexp"
  15. title changed to: "unexpected non greedy matching behaviour"
  16. type changed to: "Bug"