lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 12/12/14 01:43 PM, Dirk Laurie wrote:
2014-12-12 15:49 GMT+02:00 Thiago L. <fakedme@gmail.com>:
(I find it more intuitive than `for from, match1, match2, to`)
function tweak(f)
    return function()
       local a,b,c,d = f()
       if d then return a,d-1,b,c end
    end
end

S="The quick brown fox jumps over the lazy dog"
pat="()(%S+)%s+(%S+)()"

for from,to,match1,match2 in tweak(S:gmatch(pat)) do
    print(from, to, match1, match2)
end

What if I want to be able to stick any pattern on it without having to write a new one every time?

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.