Palindrome Checker...stumped

Ok I’m stumped
My code is comparable to the Intermediate solution but I’m still not passing several of the tests
I’d appreciate any help to point me in the right direction

function palindrome(str) {
  var regEx = /\s\W_/g;
  var newStr = str.toLowerCase().replace(regEx, "");

  for (var i = 0; i < newStr.length/2; i++){
    if (newStr[i] !== newStr[newStr.length - 1 - i]){
      return false;

  // Good luck!
  return true;

The regex is not the same as any of the solutions, they are all using something you are not using. If you have looked at the solutions, look again and check your regex against them.

Yes that was the problem I missed the square brackets

This regular expression will only replace instances where a non-word character is immediately preceded by a white space character and immediately followed by the underscore character.

A string like “eye" would not be matched. However a string like " e ?“ye” would match the " ?_” and replace it with “” resulting in “eye”.

Also, the \s is not needed, because the \W takes care of white spaces also.

Lastly, the use of brackets for a character set is not needed either. You could use | like:


Thanks for the tip, adding in the square brackets solved the problem so the regEx should match spaces and non-word characters…

Also thanks for the edits

I was just letting you know that spaces are non-word characters, which is why you do not have to include the \s before the \W inside the brackets.