string.find("().%+-*?[]^$",char)
except if it is a "magic character", it will error as the pattern is invalid.My latest attempt uses pcall, but I was wondering if there is a better way.
string.find("().%+-*?[]^$",char)
except if it is a "magic character", it will error as the pattern is invalid.
local tbl = { ["{"] = true, ["["] = true, ["%"] = true} --#Etc
--#Might be easier to use a string.char loop though.
if tbl[char] then
--#One of the magic chars
else
--#not
end
local textTbl = {36,37,40,41,42,43,45,46,63,91,93,94}
--# $%()*+-.?[]^
local charTbl = {} --#This table is the one you would use
for a,v in ipairs(textTbl) do
charTbl[string.char(v)] = true
end
He's looking for a single character, the way he's got it would be technically correct if he escapes char. Mind you if he escapes say the letter w, then he might have different problems.I can't test it right now but I believe you can use "%" to escape it like
string.find(char, %.) –Checks for dot/period
I think your big problem is your arguments are backwards. It's string.find(string, pattern)
–snip–
I am checking to determine if it is a "magic character", not fix the pattern.–snip–
Yea, that is what I was assuming, but I really didn't want to have to do it that way, it gets really annoying to type out the table. But, as you did it for me…. :)/>–snip–
string.find("().%+-*?[]^$", char, 1, true)
Ohh, thanks! That makes it much easier.string.find("().%+-*?[]^$", char, 1, true)
If the third argument is true it isn't interpreted as a pattern.
string.match("().%+-*?[]^$","%",1,true)
malformed pattern (ends with '%')