lua-users home
lua-l archive

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

On 12/12/14 04:18 PM, Dirk Laurie wrote:
2014-12-12 17:57 GMT+02:00 Thiago L. <>:

What if I want to be able to stick any pattern on it without having to write
a new one every time?
What about putting some thought into answering your own questions
before running to the list? You are not a beginner by any means.

I was having issues making it work properly... but I finally managed to do it (stateless)

local findpairs
  local function _findnext(stringandpattern, index)
    -- only branch if index = 0
    if index > 0 then
      -- this should always give a match,
      -- as we're starting from the same index as the returned match
local x,y = string.find(stringandpattern[1], stringandpattern[2], index)
      return string.find(stringandpattern[1], stringandpattern[2], y+1)
return string.find(stringandpattern[1], stringandpattern[2], index + 1)
  function findpairs(string, pattern)
    return _findnext, {string, pattern}, 0

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.