Re: Question about perlreref - are {n} and {n}? different?



usenet@xxxxxxxxxxxxxxx schreef:
> perlreref::QUANTIFIERS says:
>
> Quantifiers are greedy by default -- match the longest leftmost.
> Maximal Minimal Allowed range
> ------- ------- -------------
> {n,m} {n,m}? Must occur at least n times but no more than m times


The 'Must occur ... no more than m times' is not accurate.

#!/usr/bin/perl -w
use strict;

my $s = 'a'x100; # is more than 50 times

sub run {
local ($,, $\) = (' ', "\n");
my $re; ($re, $_) = @_;
s/$re/$1/;
print length, length($1);
}

run 'a{10,50}?(.*)' , $s;
run 'a{10,50}?(.*?)a', $s;
run 'a{10,50}?(.*?)' , $s;
run 'a{10,50}(.*?)' , $s;
run 'a{10,50}(.*)' , $s;

output:
90 90
89 0
90 0
50 0
50 50

--
Affijn, Ruud

"Gewoon is een tijger."
.



Relevant Pages

  • Question about perlreref - are {n} and {n}? different?
    ... Quantifiers are greedy by default -- match the longest leftmost. ... if you stipulate an exact count, so you can't negate greediness if you ...
    (comp.lang.perl.misc)
  • Re: [OT]Regex zum n-ten...
    ... regex definiert sein, damit nach dem ersten Schluss ist? ... Greedy quantifiers try to match as much as possible, and reduce the amount they match only if forced to by later failures. ... Lazy quantifiers match as little as possible, and only expand if required by a later failure. ...
    (de.comp.lang.java)
  • Re: [OT]Regex zum n-ten...
    ... > Quantifiers are classified as greedy or lazy. ... > X* X must match zero or more times. ...
    (de.comp.lang.java)
  • Re: java.util.regex.Pattern - general question
    ... Angus Parvis wrote in ... Greedy ... Reluctant ...
    (comp.lang.java.help)