Search code examples
lualua-patterns

Find any special characters in a string


I still struggle big time to match a string that contains the special characters (punctuation, underlines, etc). How can I make it work with patterns?

if string.match(mystr, '???') ~= nil then
  print('Invalid characters.')
end

Solution

  • Character sets [...] are your friend here.

    .*[@!#$%^&*()?<>].*