Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 4c12dfb3b7dbd4a3e4e0da1a5eeff10f7c2065d1979ef471f97abd068208b49d
Ticket: 3574242fffffffffffffffffffffffffffffffff
exact match is greedy by reluctant exact match quantifier
User & Date: sebres on 2019-11-22 20:24:39
Changes

  1. icomment:
    After pretty productive discussion in tclchat with Andrew Gierth (RhodiumToad) we have new other findings now.
    
    The new handling of quantifier "+" (in contrary to "*") as well as "{1,}" (in contrary to "{0,}") makes impossible to retrieve indices of last successful matched capturing groups, which results to impossibly to differentiate which sub-group (expression) causes the match exactly.
    
    I hope following example would illustrate that:
    
    <pre>
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a?)*</b>|<b style="color:blue">(b?)*</b>)</b>*}</b> aaa
        <b style="background-color:#dfd">{0 2} <b style="background-color:#dff">{0 2} <b style="color:red">{2 2}</b></b></b> <b style="color:blue">{-1 -1}</b>
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a?)*</b>|<b style="color:blue">(b?)*</b>)</b>+}</b> aaa
        <b style="background-color:#dfd">{0 2}</b> <b style="background-color:#dff">{3 2}</b> <b style="color:red">{-1 -1}</b> <b style="color:blue">{-1 -1}</b>
    </pre>
    
    So it is basically impossible to differentiate which of last child sub-group <b style="color:red">(a?)*</b> or <b style="color:blue">(b?)*</b> caused a match of the parent (which is also mistakenly an empty match outside of string - <b style="background-color:#dff"><code>{3 2}</code></b>), as well as the to retrieve the last indices for that, because both are <b><code>{-1 -1}</code></b>, if "+" quantifier was used in some parent expression.
    
    The same is valid for this (note the "*" instead of "?" in both last nesting groups):
    <pre>
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a*)*</b>|<b style="color:blue">(b*)*</b>)</b>*}</b> aaa
        <b style="background-color:#dfd">{0 2} <b style="background-color:#dff">{0 2} <b style="color:red">{0 2}</b></b></b> <b style="color:blue">{-1 -1}</b>
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a*)*</b>|<b style="color:blue">(b*)*</b>)</b>+}</b> aaa
        <b style="background-color:#dfd">{0 2}</b> <b style="background-color:#dff">{3 2}</b> <b style="color:red">{-1 -1}</b> <b style="color:blue">{-1 -1}</b>
    </pre>
    
    Either one would expect the same result as using "*" instead of "+" here.<br/>
    Or if the decision is sub-expression matches empty string, the indices shall be still inside the parent (empty but not outside), so we should get something like this for both cases with "+" quantifier:<br/>
    <pre>
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a?)*</b>|<b style="color:blue">(b?)*</b>)</b>+}</b> aaa
        % regexp -indices -inline <b style="background-color:#dfd">{<b style="background-color:#dff">(<b style="color:red">(a*)*</b>|<b style="color:blue">(b*)*</b>)</b>+}</b> aaa
        <b style="background-color:#dfd">{0 2} <b style="background-color:#dff">{2 1} <b style="color:red">{2 1}</b></b></b> <b style="color:blue">{-1 -1}</b>
    </pre>
    
    Andrew is also going to file this as a Postgres bug...<br/>
    Here is [https://www.postgresql.org/message-id/16133-a8934caee4e53035%40postgresql.org|the issue in PG].
    
  2. login: "sebres"
  3. mimetype: "text/x-fossil-wiki"