Garrett Wollman wrote, on 25 Sep 2024:
>
> <<On Wed, 25 Sep 2024 09:15:24 +0100, "Geoff Clare via austin-group-l at The 
> Open Group" <[email protected]> said:
> 
> > Looks like a bug in perl.
> 
> Perl is the *origin* of "non-greedy" REs.  To the extent any other
> implementation disagrees with what Perl did 25 years ago, either that
> implementation is wrong, or there was no consensus among
> implementations and it should not have been standardized.

My "looks like a bug in perl" reply was to a result that was actually
a bug in the command tested, not in perl.

However, if perl is the origin of the non-greedy modifier then that
would point to perl as the origin of the shortest vs. least repetitions
issue.  And that does indeed seem to be the case.  Looking at
https://perldoc.perl.org/perlre it says:

    By default, a quantified subpattern is "greedy", that is, it will
    match as many times as possible (given a particular starting
    location) while still allowing the rest of the pattern to match.
    If you want it to match the minimum number of times possible,
    follow the quantifier with a "?".

This, of course, states incorrectly how greedy subpatterns work.  They
don't match "as many times as possible", they give the longest
possible match.  The code doesn't match the documentation.

There are two conventions for greedy/non-greedy that make sense:

1. Greedy is longest, non-greedy is shortest.

2. Greedy is as many times as possible, non-greedy as few times as possible.

Convention 1 is used for greedy everywhere (as far as I know). By
mixing up the conventions when implementing non-greedy REs, perl has a
design flaw that others have copied, but tre has not copied and instead
done it right.

-- 
Geoff Clare <[email protected]>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England

    • Re: [10... Niu Danny via austin-group-l at The Open Group
      • Re:... Geoff Clare via austin-group-l at The Open Group
        • ... Niu Danny via austin-group-l at The Open Group
          • ... Geoff Clare via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
    • Re: [10... Steffen Nurpmeso via austin-group-l at The Open Group
      • Re:... Geoff Clare via austin-group-l at The Open Group
        • ... Harald van Dijk via austin-group-l at The Open Group
        • ... Garrett Wollman via austin-group-l at The Open Group
          • ... Steffen Nurpmeso via austin-group-l at The Open Group
          • ... Geoff Clare via austin-group-l at The Open Group
            • ... Geoff Clare via austin-group-l at The Open Group
        • ... Steffen Nurpmeso via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
    • Re: [10... Niu Danny via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group
  • [1003.1(2024... Austin Group Bug Tracker via austin-group-l at The Open Group

Reply via email to