7

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"
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Wryte
  • 885
  • 2
  • 10
  • 23

1 Answers1

8

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

string.gsub("$44,000.00", "%$", "what")
Yu Hao
  • 119,891
  • 44
  • 235
  • 294