remove all non-alphanumeric characters from lua string

polski picture polski · May 6, 2013 · Viewed 10.6k times · Source

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?

Answer

Paul Kulchenko picture Paul Kulchenko · May 7, 2013

Use gsub (as suggested by Egor Skriptunoff):

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