Wordfilter in Lua
I've been getting bored lately so I've decided to create a wordfilter in Lua, it's really basic actually, but useful. The concept goes something like this. You take a list of naughty words, and filter them out of the text.
This filter goes out a bit more advanced then that however. It's punctuation aware and have a few wildcard filter rules. For example, say we want to filter the word boo out of the text, we have several distinct filter rules that we can use.
Here's the texts to be filtered.
"boo... text"
"oboo... text"
"booo... text"
"obooo... text"
Rule 1:
Filter:"boo" => Will only return true if the word boo is found in the text.
Result:
- "boo... text" - True
- "oboo... text" - False
- "booo... text" - False
- "obooo... text" - False
Rule 2:
Filter:"*boo" => Will only return true if the substring boo is found at the end of a word in the text.
Result:
- "boo... text" - True
- "oboo... text" - True
- "booo... text" - False
- "obooo... text" - False
Rule 3:
Filter:"boo*" => Will only return true if the substring boo is found at the begining of a word in the text.
Result:
- "boo... text" - True
- "oboo... text" - False
- "booo... text" - True
- "obooo... text" - False
Rule 4:
Filter:"*boo*" => Will only return true if the substring boo is found anywhere in the text.
Result:
- "boo... text" - True
- "oboo... text" - True
- "booo... text" - True
- "obooo... text" - True
Usage:
- Add the filter rules in the badwords.txt file, remember to close each rule with a comma
- Put dofile("filter.lua") in your file, remember to put filter.lua, string.lua, table.lua, and badwords.txt in the same directory.
- Use filter(Text) as the filter function, it will return either true or false. If it returns true, then the filter will have detected naughty words in the text






