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

  • I still find the res... Niu Danny via austin-group-l at The Open Group
    • Re: I still fin... Niu Danny via austin-group-l at The Open Group
      • Re: I still... Geoff Clare via austin-group-l at The Open Group
        • Re: I s... Niu Danny via austin-group-l at The Open Group
    • Re: I still fin... Geoff Clare via austin-group-l at The Open Group
      • Re: I still... Niu Danny via austin-group-l at The Open Group
        • Re: I s... Geoff Clare via austin-group-l at The Open Group
          • Re:... Niu Danny 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
              • ... Niu Danny 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

Reply via email to