lua-users home
lua-l archive

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

On Feb 16, 2018, at 8:04 AM, Dirk Laurie <> wrote:

> 2018-02-16 14:13 GMT+02:00 albertmcchan <>:
>> I post this about a month ago.  I've found a simple lpeg re pattern for above
>> It can handle "repeated" separactor too, say, "(.*)andand(.*) too.
>> pat = re.compile( "{ (.(g <- &%z / .g))* } %z {.*}", { z = 'and' } )
>> note: the loop never match the first position, but it is ok
>> the second %z take care of of text with %z up front.
> Just remind me ... since `lpeg` and `re` are packages you need
> to load into Lua, and standard Lua comes with a string library,
> why on earth would you want to do things in `re` that Lua can
> already do very well without it?

you are right.

If all I wanted were captures of "(.*)and(.*)", I would use string.match
I had picked the simple pattern to learn about lpeg matching.

But ... what if z = re.compile " 'and' %s+ ('possibly' / 'likely' / 'definitely') %s+ " ?
or, possibly even more complicated ?

Above lpeg re pattern can handle it