What is the purpose of [\w]?

Tell us what’s happening:

guyz… what is [\W] means?

Your code so far

function palindrome(str) {
  // Good luck!
 return str.replace(/[\W_]/g, '').toLowerCase() === str.replace(/[\W_]/g, '').toLowerCase().split('').reverse().join('');

  
}



palindrome("eye");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/check-for-palindromes

https://www.w3schools.com/jsref/jsref_regexp_wordchar_non.asp

1 Like

Tell us what’s happening:

why is the purpose of putting an underscore in expression [\W_]?

Your code so far

function palindrome(str) {
  // Good luck!
 return str.replace(/[\W_]/g, '').toLowerCase() === str.replace(/[\W_]/g, '').toLowerCase().split('').reverse().join('');

  
}



palindrome("eye");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge: