develooper Front page | perl.beginners | Postings from March 2023

Re: A Regular Expression Problem in Perl 5.28

Thread Previous
From:
Uri Guttman
Date:
March 28, 2023 22:46
Subject:
Re: A Regular Expression Problem in Perl 5.28
Message ID:
16d6a4be-174e-a043-d1af-023f3d83210e@perlhunter.com
On 3/28/23 18:00, Martin McCormick wrote:
> Uri Guttman <uri@perlhunter.com> writes:
>> yes, but he kept the {5,} repeat count. so i just kept it too.
> 	Now that I know how this works, I will probably change to
> {4,} as this would match 4 or more digits.  From reading the
> documentation, {4} means 4 and only 4.  {4,6} means 4 but nothing
> else except 6. {N,} means N as a low limit but any number higher.

you got most of it. but {4,6} means any length from 4 to 6. 5 is fine 
there.

think of it as a low and high pair of lengths. the left one is the 
shortest count and the right side is the longest.

if you have only {4}, that is the same as {4,4}.

{5,} is 5 or more (high count is infinity, sort of).

{,5} is {0,5} or any number of repeats up to 5.

+ is just {1,} 1 or more
* is just {0,} 0 or more
? is just {0,1} 0 or 1 - makes that part optional

and don't forget that any quantifier can modify any thing before it. 
that is more than just single chars. if you group something, you can 
apply a quantifier to it.

uri



-- 
https://uriguttman.blogspot.com/
A Long Strange Trip
A blog about computers, food, my life and silliness.


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About