Overview
| Artifact ID: | 80b00c7c7b8a218ebf1b97c267f37b627bf829e0b36ed11c3f5ee5aa75600809 |
|---|---|
| Ticket: | 3574242fffffffffffffffffffffffffffffffff
exact match is greedy by reluctant exact match quantifier |
| User & Date: | sebres on 2019-11-22 17:13:34 |
Changes
- icomment:
If the issue is "caused" because RE-engine following main rule "greediness of topmost expression wins" or like a Kevin's statement: <blockquote><i>A general rule is that the greediness of the outermost quantifier determines the greediness of everything in the subexpression.</i></blockquote> it could explain why initially non-greedy subexpression grows, even to fulfill the whole match be greedy. So for example here the first capturing group grows to whole match, the second (inner) group capturing <b style="color:blue"><code>aaaf</code></b> and <b style="color:#A09"><code>aaf</code></b> each after other (so ultimately gets the value of the last one). <pre> % regexp -inline {((a*f)*?)<b>?</b>} <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:#A09">aaf</b> </pre> But there is just another example illustrating that this "concept" is not completely correct: <pre> % regexp -inline {((a*f)*?)<b style="color:green">*</b>} <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:#A09">aaf</b> <b style="color:#A09">aaf</b> % regexp -inline {((a*f)*?)<b style="color:red">+</b>} <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> <b style="color:blue">aaaf</b><b style="color:#A09">aaf</b> {} {} </pre> Both of topmost quantifiers (red/green) are greedy, the whole expression is greedy.<br/> The whole result corresponds greedy whole match (matches the whole string in both cases).<br/> But in the second case the groups are empty (so it is somehow non-greedy anymore).<br/> So the (more aggressive) quantifier <code>+</code> behaves <b>fewer</b> greedy as (fewer aggressive) quantifier <code>*</code> inside the capturing groups. - login: "sebres"
- mimetype: "text/x-fossil-wiki"