Quick way to extract alphanumeric characters from a string in Javascript -


i know can write simple loop check each character in string , see if alphanumeric character. if one, concat new string. , thats it.

but, there more elegant shortcut so. have string (with css selectors precise) , need extract alphanumeric characters string.

many ways it, basic regular expression replace

var str = "123^&*^&*^asdasdsad";  var clean = str.replace(/[^0-9a-z]+/gi,"");  console.log(str);  console.log(clean);


Comments