How to replace a $ in a Lua string

lualua-patternsstring

How do you replace a dollar sign in Lua since it is a special character in pattern matching?

I've tried this:

string.gsub("$44,000.00", "$", "")
> "$44,000.00"

But all it does is add a blank at the end of the string. For example

string.gsub("$44,000.00", "$", "what")
> "$44,000.00what"

Best Answer

Knowing $ is a special character is half way to the answer. Use % to escape magic characters:

string.gsub("$44,000.00", "%$", "what")