lua-users home
lua-l archive

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


On Jan 25, 2018, at 8:03 PM, Sean Conner <sean@conman.org> wrote:

>  If you are looking for a final "and" (which ends the input), then this
> works:
> 
>    last_and = P"and" * P(-1)
>    char     = R("\0\96","b\255")^1
>                 + -last_and * P"a"
>    pat      = C((char)^0) * last_and
> 
>    print(pat:match(string.rep("this and that land",400) .. "and"))
> 

your example also shows usefulness of undo lpeg.U (if exist):

pat = C( P(1)^3 * U(3) * #P'and' )