Need help with the RegEx for my Palindrome project solution

I just passed the test for the 1st project but I don’t like the RegEx I had to use.:

const alphaNumOnly = str.toLowerCase().split(/[^A-Z-a-z\d]/).join('').split(/[-]/).join('')

On RegExr [^A-Za-z\d] matched everything but when I ran a check in the console I was getting 2 dashes for the test palindrome("0_0 (: /-\ :) 0-0") . So I had to tack on another split.

What did I miss in my regular expression, or is it a bug with VS Code?

And is it okay to post part of the code for a project solution?

Never mind - I missed 2 things: 1) having A-Z when I already set the string to lower case and the - after it. My RegEx of /[^a-z\d]/ now works.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.