regex - JavaScript Check for palindrome (spaces & punctuation included) -


trying check palindromes. i've checked other answers none included punctuation & spaces.

"never odd or even" , "a man, plan, canal. panama" should return true don't.

   function palindrome(str) {   if(str.replace(/[^\w\s]|_/g, "").tolowercase() === str.replace(/[^\w\s]|_/g, "").tolowercase().split("").reverse().join("")){     return true;   } else {     return false;   } } palindrome("eye"); 

i think have error in regex. if want remove spaces, don't need \s. try changing:

str.replace(/[^\w\s]|_/g, "") 

with

str.replace(/[^\w]|_/g, "") 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -