I'm trying to search a string for a set of values and return the value ONLY if the string matches exactly with one of the set.
My original expression was as so:
title = "MrS"
setTitles = {"Miss", "Mr", "Mrs", "Dr", "Ms"}
title = (title:gsub("%w",string.lower)):gsub("^l", string.upper)
if string.match(title, setTitles) ~= nil then title = title else title = "XX" end
I then realised I needed some way of cycling through the values so got to here:
title = "MrS"
setTitles = {"Miss", "Mr", "Mrs", "Dr", "Ms"}
title = (title:gsub("%w",string.lower)):gsub("^%l", string.upper)
for i = 1, 5 do
if string.match(title, setTitles[i]) ~= nil
then title = title
else title = "XX"
end
end
Except that just returns "XX" every time.
I know it's probably quite simple and obvious, but I can't seem to find a solution and would really appreciate a hand!