Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace a $ in a Lua string?

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"
like image 491
Wryte Avatar asked Jun 16 '14 13:06

Wryte


1 Answers

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

string.gsub("$44,000.00", "%$", "what")
like image 197
Yu Hao Avatar answered Oct 01 '22 06:10

Yu Hao