Re: regex
[email protected] Mon, 22 Jan 2024 13:59:21 +0100 (CET)
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
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