lua-users home
lua-l archive

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


To test if a string exactly matches one of a list of strings, I would do:

local function set(t) -- standard helper function to create a set from a list
  local s = {}
  for k, v in pairs(t) do
    s[v] = true
  end
  return s
end
local valid_set = set {"4", "44", "22", "445"}
local function string_matches(s)
  return not not valid_set[s]
end

On Fri, Nov 14, 2008 at 11:36 AM, Pete Kay <petedao@gmail.com> wrote:
Hi,
 
I am struggling with trying to match regex agains string.  Let's say I have a reg that looks like 4|44|22|445, basically a bunch of arbitrary numbers.  Is that any Lua function that can tell me if a string match exactly one of those numbers?
 
Any suggestion will be great.
 
Thanks,
Pete