Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  178] [ 2]  / answers: 1 / hits: 31699  / 9 Years ago, fri, january 8, 2016, 12:00:00

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);

More From » regex

 Answers
64

Use .replace(/_/g, ) to remove all underscores or use .replace(/_/g, ) to replace them with a space.



Here is an example to remove them:





var str = Yeah_so_many_underscores here;
var newStr = str.replace(/_/g, );
alert(newStr);




[#63800] Wednesday, January 6, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anitamaeg

Total Points: 466
Total Questions: 106
Total Answers: 106

Location: Suriname
Member since Sun, Jun 13, 2021
3 Years ago
;