6

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?

polski
  • 61
  • 1
  • 1
  • 2

2 Answers2

11

Use gsub (as suggested by Egor Skriptunoff):

str = str:gsub('%W','')
Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
-1

just make it like this you forgot +

if(str:match("%W+")) then --if it contain alpha
     number = str:match("%d+")
     alpha = str:match("%W+")
 end
Master
  • 11
  • 2