I can't figure out how to take out a comma from a string and make it only as one number.
print(string.match('Cost: $2,501', '(%d+)%z?,%z?(%d+)')) -- Output: 2 501 -- It gives two numbers instead of just one.
It's most likely something string.match
does automatically when separating sets.
You can simplify the string pattern you're using by using gmatch
:
local str = "" for i in ("Cost: $2,501"):gmatch("%d+") do str = str .. i end print(str)
You could replace the comma using gsub and then match for any digits. Like so
print(string.match(string.gsub("Cost: $2,501", ",", ""), "%d+"))