How to strip all non alphanumeric characters from a string in c++?

Write a function that takes a char and returns true if you want to remove that character or false if you want to keep it: bool my_predicate(char c); Then use the std::remove_if algorithm to remove the unwanted characters from the string: std::string s = “my data”; s.erase(std::remove_if(s.begin(), s.end(), my_predicate), s.end()); Depending on your requirements, you … Read more

Regex for checking if a string is strictly alphanumeric

Considering you want to check for ASCII Alphanumeric characters, Try this: “^[a-zA-Z0-9]*$”. Use this RegEx in String.matches(Regex), it will return true if the string is alphanumeric, else it will return false. public boolean isAlphaNumeric(String s){ String pattern= “^[a-zA-Z0-9]*$”; return s.matches(pattern); } If it will help, read this for more details about regex: http://www.vogella.com/articles/JavaRegularExpressions/article.html

How to remove all non-alpha numeric characters from a string in MySQL?

Using MySQL 8.0 or higher Courtesy of michal.jakubeczy’s answer below, replacing by Regex is now supported by MySQL: UPDATE {table} SET {column} = REGEXP_REPLACE({column}, ‘[^0-9a-zA-Z ]’, ”) Using MySQL 5.7 or lower Regex isn’t supported here. I had to create my own function called alphanum which stripped the chars for me: DROP FUNCTION IF EXISTS … Read more

tech