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



Juha Laiho schreef:
> Dr.Ruud:

>>> 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.
>
> Hmm.. given a little bit more context, it is accurate:
>
> AX{n,m}B

Yes, but not in general.

echo 'AXXXXXXXXB' |
perl -ne 'chomp; print "$_:OK\n" if /AX{2,3}/;'


Compare perlre(1)

{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times

Compare grep(1)

{n} The preceding item is matched exactly n times.
{n,} The preceding item is matched n or more times.

{n,m} The preceding item is matched at least n times,
but not more than m times.

So perlreref(1) could use one of those.

--
Affijn, Ruud

"Gewoon is een tijger."
.