remove '$' characters from a string
Asked Answered
H

1

10

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,'$','').

Heliotrope answered 13/9, 2013 at 16:47 Comment(0)
H
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
Hypolimnion answered 13/9, 2013 at 16:50 Comment(2)
@Heliotrope please, accept Mike's answer if it solved your problem.Cotten
General 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.Hawse

© 2022 - 2024 — McMap. All rights reserved.