Overview
| Artifact ID: | 5bef2df79f840a64bd4aa04f87bdb282cf87f92303d33b34b54a452fe90502f8 |
|---|---|
| Ticket: | 3574242fffffffffffffffffffffffffffffffff
exact match is greedy by reluctant exact match quantifier |
| User & Date: | sebres on 2019-11-22 14:52:40 |
Changes
- closer changed to: "nobody"
- comment changed to:
Possible bug, cause IMO that should match the same: Or a documentation bug - according to documentation "{m}?" is ungreedy quantifier. % regexp -inline {((?:ab|abc){1}?)(cd|d){1}?} abcd abcd abc d % regexp -inline {((?:ab|abc){1,1}?)(cd|d){1,1}?} abcd abcd ab cd - icomment:
A fresh concern regarding the issue and new findings after discussion in tclchat with pooryorick. The issue could be explained with following sentence from the documentation:<br/> <blockquote><i>A quantified atom with quantifier {m} or {m}? has the same preference (possibly none) as the atom itself. A quantified atom with other normal quantifiers (including {m,n} with m equal to n) prefers longest match. A quantified atom with other non-greedy quantifiers (including {m,n}? with m equal to n) prefers shortest match.</i></blockquote> But the fact that <code>{m,n}</code> prefers the shortest match doesn't mean that the sub-expression it is applied to should prefer the shortest match (at least, it doesn't necessarily mean that). <hr> Another interesting set of examples which can be related to the same issue: <pre> % regexp -inline {(t*?)?} ttt ttt <b style="color:green">t</b><b style="color:red">tt</b> % regexp -inline {(t*)?} ttt ttt ttt </pre> Although it behaves like described in the documentation:<br/> <blockquote><i>A branch has the same preference as the first quantified atom in it which has a preference. An RE consisting of two or more branches connected by the | operator prefers longest match.</i></blockquote> But it does not explain why the group is expanded to the whole match, as well as the difference to this counter-example: <pre> % regexp -all -inline {(t)*} ttt ttt <b style="color:green">t</b> </pre> So the change to greedy quantifier of RE seems to affect capturing behavior of (initially) non-greedy group, compared to (initially) greedy group. <hr> FWIW, maybe following would explain the reason (or rather the necessity) why or for which cases the sub-branch (group) could be non-greedy (why this can be expected or used): <pre> % regexp -inline {(t*?(\w+))?} ttxx ttxx ttxx ttxx % regexp -inline {(t*(\w+))?} ttxx ttxx ttxx xx </pre> But that all still don't explain the growth of captured non-greedy group to the whole match. - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- severity changed to: "Minor"