lua-users home
lua-l archive

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


discovered an elegant recursive lpeg re pattern that is fast
and safe for long string (it does not backtrack)

t = "this and that and whatever"

-- lua pattern "(.-)and(.*)
= re.match(t, "{g <- &('and') / .g} 'and' {.*}"
this
that and whatever

-- lua pattern "(.*)and(.*)
= re.match(t, "{g <- &('and' (!'and' .)* !.) / .g} 'and' {.*}"
this and that
whatever