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?
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.
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.
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.
Non-alphanumeric characters are characters that are not numbers (0-9) or alphabetic characters.
Use gsub (as suggested by Egor Skriptunoff):
str = str:gsub('%W','')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With