简体   繁体   中英

remove all non-alphanumeric characters from lua string

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?

使用gsub (根据 Egor Skriptunoff 的建议):

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM