string.gsub and $ ?

So for some reason, this happens:

[lua]print( string.gsub( “test”, “$”, “s” ) )
–Output: tests 1

print( string.gsub( “test”, “$”, “Wat” ) )
–Output: testWat 1

print( string.gsub( “”, “$”, “I don’t even” ) )
–Output: I don’t even 1

I think it’s because represents a pattern? If so - how do I avoid this to search for the actual ?

matches the end of a [del]string[/del]line, you'll want to escape it to match the dollar sign character. Try matching % (Lua uses % for escaping in patterns)

[editline]30th March 2016[/editline]

(On a related note, ^ matches the beginning of a [del]string[/del]line, be wary of multiline strings)

Lua Patterns

string.gsub( text , replace any matchs , with this )
string.gsub(“Hello Potato.”,“Potato”,“World”) = “Hello World”
string.gsub(“Hello”,""," World.") = "Hello World." -- because "" matches with the end of the text.