Created
August 8, 2019 12:58
-
-
Save ChaunceyHoover/157a363455d0b88c4ac76fcd0909a599 to your computer and use it in GitHub Desktop.
A simple pattern/filter generator. Could be useful for a blacklist of words or something, probably.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function case_insensitive_pattern(pattern) | |
local p = pattern:gsub("(%%?)(.)", function(percent, letter) -- match regex | |
if percent ~= "" or not letter:match("%a") then | |
-- if % is matched or 'letter' is not a letter | |
return percent .. letter | |
else | |
return string.format("[%s%s]", letter:upper(), letter:lower()) | |
end | |
end) | |
return p | |
end | |
--[[ | |
EXAMPLE | |
======= | |
pattern = case_insensitive_pattern("heck") | |
print(("heck HeCk HECK HECKIN"):gsub(pattern, "****")) --> **** **** **** ****IN | |
]]-- |
Really only useful if you're making like a chat filter or something
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just importing old pastebin scripts to my gist