With the following code i am trying to remove certain characters, including dots. It works fine when i replace the dot with any other character to remove, but when i want to remove dots it just returns an empty string. anyone know why and how to fix it?
local pure,match = string.gsub('Hi!? This is a test.','!','')
pure,match = string.gsub(pure,'?','')
pure,match = string.gsub(pure,'.','')
print(pure)
I also noticed that for some reason when i want to make it replace dots it replaces all characters.
Here ! I canβt really explain why but this will works
local pure,match = string.gsub(βHi!? This is a test.β,β!β,ββ)
pure,match = string.gsub(pure,β?β,ββ)
pure,match = string.gsub(pure,β%.β,ββ)
print(pure)
2 Likes
thank you! I knew it had something to do with string formatting but i couldnt figure out what
1 Like
. is a magic character, meaning a special character that does a specific thing, in this case it just matches any character. % is the escape character, so instead of matching any character it will match literally β.β. You can also shorten this by using groups.
local input = "Hi!? This is a test."
local pure = string.gsub(input, "[%.!?]", "");
7 Likes