Remove all non-alphanumeric characters from lua string

alphanumericluanon-alphanumeric

I checking string for a non-alphanumeric char.

if(str:match("%W")) then
  --make str alpha-numeric
end

How to remove all non-alphanumeric chars from string using lua?

Best Answer

Use gsub (as suggested by Egor Skriptunoff):

str = str:gsub('%W','')