[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to translate lua pattern "(.*)and(.*)" with lpeg re ?
- From: Andrew Gierth <andrew@...>
- Date: Sun, 21 Jan 2018 03:07:29 +0000
>>>>> "albertmcchan" == albertmcchan <albertmcchan@yahoo.com> writes:
albertmcchan> looks like it is not easy to convert lua pattern
albertmcchan> "(.*)and(.*)" after all my last attempt, re.compile
albertmcchan> "{(!'and' .)*} 'and' {.*}" was close, but still wrong
albertmcchan> the re pattern correspond to lua pattern "(.-)and(.*)",
albertmcchan> not the greedy version.
These work, but I have no idea which is best (I'm still new to lpeg):
{ ((!'and' .) / 'and' &( (!'and' .)* 'and' ))* } 'and' {.*}
or
{ ((!'and' .)+ / 'and' !( (!'and' .)* !. ))* } 'and' {.*}
or
-- any nonempty string not containing 'and'
not_and = (1 - P('and'))^1
-- match 'and' only as long as there's a following 'and' somewhere
and_and_and = P('and') * -(not_and^-1 * -1)
pattern = C((not_and + and_and_and)^0) * P('and') * C(P(1)^0)
--
Andrew.