"Stuck on Palindrome Checker project - regex not matching special characters"

Hey everyone! I’m working on the Palindrome Checker project
and running into an issue with my regex pattern.

My code strips spaces and punctuation like this:

function palindrome(str) {
let cleanStr = str.toLowerCase().replace(/[^a-z0-9]/g, ‘’);
return cleanStr === cleanStr.split(‘’).reverse().join(‘’);
}

It passes most test cases, but fails on strings with
underscores. Can anyone point out what I’m missing?

Thanks in advance!

Hi @jefferson.bahian,

Here is a good Regular Expression Tester to test with.

If you need more help, please click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Happy coding