remove '$' characters from a string

Richard picture Richard · Sep 13, 2013 · Viewed 8.1k times · Source

I am trying to remove '$' signs from a string, but I am guessing it is some special char? I am extremely new to lua (just started coding in it today). From my understanding this should work and does for other chars string.gsub(line,'$','').

Answer

Mike Corcoran picture Mike Corcoran · Sep 13, 2013

yup, that's a special character for pattern matching. you need to escape it with the % symbol.

local s = 'asdf$erer$iiuq'
print(s:gsub('%$', ''))

> asdfereriiuq  2