[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: Mon, 22 Jan 2018 15:01:12 -0500
i added re.upto function in lpeg re.lua
function re.upto(what, greedy)
local fmt = string.format
local c = fmt('(!(%s).)', what)
if greedy then c = fmt('((%s) !(%s* !.) / %s+)', what, c, c) end
return fmt({%s*} (%s) ', c, what)
end
text = 'this and that and whatever'
= re.match(text, re.upto( " 'and' " ) .. "{.*}") -- non-greedy match
this
that and whatever
= re.match(text, re.upto( "[aA][nN][dD]" ) .. "{.*}") -- non-greedy case-insensitive
this
that and whatever
= re.match(text, re.upto( " 'and' ", true) .. "{.*}") -- greedy match
this and that
whatever
plain lpeg upto function if interested:
http://www.gammon.com.au/forum/bbshowpost.php?id=14149&page=2