Yes, the {}l RE modifier has the canonical form
{a,b} where a and b are numbers and so that modifies the char before it to
match from a to b times, e,g
A{1,3}
matches one, two or three As. If you leave out the first number, zero is
presumed. Hmm, perl 5.30
% perl -E 's ay(10) if "aaa"=~/a{,2}/;'
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE
in m/a{ <-- HERE ,2}/ at -e line 1.
and
% perldoc perlre
says
Quantifiers
Quantifiers are used when a particular portion of a pattern needs to
match a certain number (or numbers) of times. If there isn't a
quantifier the number of times to match is exactly one. The following
standard quantifiers are recognized:
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
(If a non-escaped curly bracket occurs in a context other than one of
the quantifiers listed above, where it does not form part of a
backslashed sequence like "\x{...}", it is either a fatal syntax error,
or treated as a regular character, generally with a deprecation warning
raised. To escape it, you can precede it with a backslash ("\{") or
enclose it within square brackets ("[{]"). This change will allow for
future syntax extensions (like making the lower bound of a quantifier
optional), and better error checking of quantifiers).
On Mon, Jan 22, 2024 at 6:59 AM <[email protected]> wrote:
> Jorge Almeida:
> > Please help me to understand this:
> > $ perl -e 'exit(10) if "aaa"=~/a{,2}/;'
> > $ echo $?
> > $ 10
>
> In man perlre, under "Regular Expressions" it says:
>
> {,n} Match at most n times
>
> So /a{,2}/ matches "", "a", and "aa" and is ignorant about what
> comes before and after (basically). That "aa" is followed by a
> "a" isn't something the expression prohibits. If you want that
> try /^a{,2}$/ instead.
>
> Regards,
> /Karl Hammar
>
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
--
a
Andy Bach,
[email protected]
608 658-1890 cell
608 261-5738 wk