lua-users home
lua-l archive

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


On Tue, Nov 6, 2012 at 4:13 PM, Xavier Wang <weasley.wx@gmail.com> wrote:
now Lua don't support ?,*,+,- on a so-called sub-pattern, but from the
source, to add this support is easy: we can add a special %r (means
recurse) modifier, so as:
("catcatcat"):match "%r(cat)+"
returns
catcatcat


I do a recursion.

function checkformat(what)
-- Lua cannot handle repeated multibyte patterns
-- i.e. [Ab]+ does not match AbAbAb...
-- this situation is handled by a recursive function
  if what=='' then return 'true' end
  _,_,mm,xx = string.find(what, "^([%u][%l]+)(%a*)")
  if mm then return(checkformat(xx))
  else
     return nil
  end
end