[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: Tue, 23 Jan 2018 14:19:57 -0500
while learning how lpeg '=>' work,
discover a faster re pattern for text with many 'and' or long string length
-- old lua pattern "(.*)and(.*)"
old_pat = re.compile "{g <- &('and' (!'and' .)* !.) / .g} 'and' {.*}"
-- new lua pattern "(.*)and(.*)"
-- speedup by not doing lookahead after 'and'
pat = re.compile(
"(g <- 'and' / .g)+ => split",
{ split = function(s,i) return true, s:sub(1, i-4), s:sub(i) end }
)
= pat:match "this and that and whatever"
this and that
whatever