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,'$','')
.
Asked
Active
Viewed 1.7k times
10

hjpotter92
- 78,589
- 36
- 144
- 183

Richard
- 15,152
- 31
- 85
- 111
1 Answers
16
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

Mike Corcoran
- 14,072
- 4
- 37
- 49
-
@Richard please, accept Mike's answer if it solved your problem. – LorenzoDonati4Ukraine-OnStrike Sep 13 '13 at 16:57
-
2General advice would be to always precede a punctuation character in a pattern with `%`. Even non-magic punctuation is guaranteed to be safely quoted by `%`. The other bit of advice is to remember that Lua patterns are not Regular Expressions. If you need the full power of a regexp, then you need to find a suitable module that wraps your favorite regexp library. – RBerteig Sep 13 '13 at 20:07