Re: how to translate lua pattern "(.*)and(.*)" with lpeg re ?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: how to translate lua pattern "(.*)and(.*)" with lpeg re ?
- From: albertmcchan <albertmcchan@...>
- Date: 2018年1月23日 09:37:28 -0500
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