[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lpeg.U ?
- From: albertmcchan <albertmcchan@...>
- Date: Thu, 25 Jan 2018 17:19:15 -0500
pat = re.compile "{g <- .g / &'and' }" -- lua pattern "(.*)and"
= lpeg.pcode( pat ) -- using debug version of lpeg
i noticed its pcode has a "behind 3" instruction to not consume the last 'and'
there is a lpeg.B function to do look-behind, but how to go back to it if B matched ?
Is there a lpeg.U(n) (for undo n characters) or something similar ?
As an example of its usefulness, say # is lpeg re for undo 1 character
REDO above re pattern, but without backtrack stack overflow problem:
NOTE: I want to capture ALL except LAST 'and'
pat = re.compile "{ (g <- 'and' / . [^a]* g)+ ### }"
Without UNDO, I have to do this (likely much slower):
pat = re.compile( "(g <- 'and' / . [^a]* g)+ -> drop3", {drop3 = function(s) return s:sub(1,-4) end} )