Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 469
polski Avatar asked May 06 '13 19:05

polski


People also ask

How do I remove all non alphanumeric characters from a string?

To remove all non-alphanumeric characters from a string, call the replace() method, passing it a regular expression that matches all non-alphanumeric characters as the first parameter and an empty string as the second. The replace method returns a new string with all matches replaced.

How do you get rid of non alphanumeric?

Non-alphanumeric characters can be remove by using preg_replace() function. This function perform regular expression search and replace. The function preg_replace() searches for string specified by pattern and replaces pattern with replacement if found.

How do you remove all non alphanumeric characters from a string in CPP?

Remove all non alphanumeric characters from a string in C++The std::remove_if algorithm returns an iterator that indicates where the end should be, which can be passed to the std::erase function. Starting with C++20, consider using the std::erase_if function that is error-free wrapper over the erase-remove idiom.

What is non alphanumeric characters?

Non-alphanumeric characters are characters that are not numbers (0-9) or alphabetic characters.


1 Answers

Use gsub (as suggested by Egor Skriptunoff):

str = str:gsub('%W','')
like image 93
Paul Kulchenko Avatar answered Dec 19 '22 11:12

Paul Kulchenko