You can use %D+ to remove all matches following the pattern of string.gsub (one or more non-numeric characters) :

S = "($1000)" res, _ = s: gsub (" % D + ", "") print (res) - = > 1000

See Lua Demo