[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: some newbie questions about lpeg
- From: "Duncan Cross" <duncan.cross@...>
- Date: Mon, 17 Sep 2007 09:34:32 +0100
On 9/16/07, gary ng <garyng2000@yahoo.com> wrote:
> What would be the equivalent of pattern{x,y} in regex,
> i.e. pattern can occur between x and y times ?
First attempt:
function lpeg.minmax(patt,min,max)
return #(lpeg.P(patt)^min) * lpeg.P(patt)^-max
end
>x = lpeg.minmax("F",5,10)
>print(lpeg.match(x,"FFFF"))
nil
>print(lpeg.match(x,"FFFFF"))
6
>print(lpeg.match(x,"FFFFFFFFFF"))
11
>print(lpeg.match(x,"FFFFFFFFFFFFFFF"))
11