Now I'm completely lost. So how about the informative text from "precedence of construct" perspective? I discussed it a few days earlier with Steffen:
> I was thinking about something like this: > > The precedence of quantifiers are as follow (from highest to lowest): > > 1. The length of any minimal quantifier -modified subexpression > shall be such that they match the shortest substring of the > subject string, in descending priority from left to right. > > 2. Consistent with rule 1, the length of the overall match shall > be the longest possible. > > 3. The length of any greedy quantifier -modified subexpression > shall be such that they match the longest substring of the > subject string, in descending priority from left to right. > 2025年3月12日 00:51,Geoff Clare via austin-group-l at The Open Group > <[email protected]> 写道: > > Niu Danny wrote, on 07 Mar 2025: >> >>> 2025年3月6日 23:06,Geoff Clare via austin-group-l at The Open Group >>> <[email protected]> 写道: >>>> >>>> >>>> >>>> e.g. `([0-9]+)+?` >>> >>> This is a pathological case because you are simultaneously asking for >>> both the longest and shortest match for the SAME part of the string. >>> Such cases ought not to occur in real-world use. >>> >>> What I meant, when I said it is not recursive, is something like: >>> >>> ([0-9]+[a-z]*)+? >>> >>> where the inner + and * are individually greedy; they don't inherit >>> the outer repetition's non-greediness. >> >> But greedy quantifiers are still nested in a non-greedy one. >> Would you say that this is also pathological, or do you >> have something else on your mind? > > Here's a better example. This uses the code from bug note 7094 > modified to take the ERE and string as arguments: > > $ ./a.out 'X(([0-9a-zA-Z]+)([a-zA-Z]*))+?Y' 'X000aaaYbbbY' > regcomp returned: 0 > regexec returned: 0 > 0 8 > 1 7 > 1 7 > 7 7 > -1 -1 > > Because [0-9a-zA-Z]+ is greedy it matched 000aaa and [a-zA-Z]* was > left matching the empty string. If the ? modifier was recursive then > [0-9a-zA-Z]+ would have matched just the first 0 and [a-zA-Z]* would > have matched 00aaa. > > -- > Geoff Clare <[email protected]> > The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England >
