There is no way to define that pattern in Lua. What I do is to use an approximation and solve the details inside a "replace" function: string.gsub(s, "^%-?%d+(%.?%d?%d?)$", function (p, s) if s == "" or string.len(s) == 3 then ... -- Roberto