Use [^A-Za-z0-9].
Note: removed the space since that is not typically considered alphanumeric.
Answer from Mirek Pluta on Stack OverflowUse [^A-Za-z0-9].
Note: removed the space since that is not typically considered alphanumeric.
Try
return value.replaceAll("[^A-Za-z0-9]", "");
or
return value.replaceAll("[\\W]|_", "");
Trying to remove non-alphabetical characters from inputted string need help pls
How to remove non-alphanumeric characters in Java?
removing all non-letter characters from a string? ((using regex))
How to erase all non alphanumeric characters from a string?
Hey guys! For class I'm trying to make a program to remove all non-alpha characters from a inputted string. Can you tell me why this isn't working?
For some reason when I input for example "testing test ! bla -o-" it outputs "testingtest!bla-o"
#include <iostream>using namespace std;int main() {
string inputStr;getline(cin, inputStr);for (int i = 0; i < inputStr.size(); i++){if (!isalpha(inputStr[i])){inputStr.replace(i, 1, "");}}cout << inputStr;return 0;}
I am currently trying this two different ways and they aren't working - I'm checking the input value and running this every time a key is pressed:
input.replace(/[^a-zA-z]/, "");
and
for(var i = 0; i < input.length; i++){
if( input[i] == /[^a-zA-z]/g){
console.log("input " + input[i] + " is not a letter!");
input.replace(input[i], "");
}
}jsfiddle here