lua-users home
lua-l archive

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


>   I have a pattern that looks like this BNF:
> 
> 	TEXT	= 'A' - 'Z' / 'a' - 'z'
> 	DIGIT	= '0' - '9'
> 
> 	pattern	= 1*TEXT [ ';' 1*DIGIT ]

Maybe like this?

  local text, sep, digit = string.match(s, "^(%a+)(;?)(%d*)$")
  if not text or (sep == "") ~= (digit == "") then
    error("bla bla bla")
  end
  return text, tonumber(digit)

-- Roberto