lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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