How to remove comma, dots etc from a string and get a table of words

Hello im trying to make a response bot whenever a player chats. But the problem im currently facing is that I cant figure out how to remove all special characters from the string and then returning a table.

Msg: “This is, a test message!”

Then having the table as following.
Table {“This”, “is”, “a”, “test”, “message”}

I can remove the spaces but the special characters stays with the words.

The simple way is with regular expressions.

local filtered = string.gsub(message, "[^%w ]", "") – fixed it

1 Like

Use the pattern "%p" to remove any punctuation

local str = "This is, a test message!"
local tbl = string.split(str:gsub("%p", ""), " ")


Thank you for the comments I will try it out tomorrow.