Like the title says, i would like to remove an underscore within a String with a regex. This is what i have:
function palindrome(str) {
str = str.toLowerCase().replace(/[^a-zA-Z]/g, '',/\s/g, '',/[0-9]/g,'');
if (str.split("").reverse().join("") !== str) {
return false;
}
else {
return true;
}
}
palindrome("eye");
toLowerCase().str = str.replace...to the variable..replace(/[^a-zA-Z]/g, '',/\s/g, '',/[0-9]/g,'')you can't usereplacelike this. You can chain them.replace(/[^a-zA-Z]/g, '').replace(/\s/g, '').replace(/[0-9]/g,''). In your case you don't need this, you can usestr.replace(/_/g, '');