Why doesn’t this assign prepClass to the string selectorClass with underscores instead of non alpha chars? What do I need to change it to?
var regex = new RegExp("/W/", "g");
var prepClass = selectorClass.replace(regex, "_");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A couple of things:
RegExpconstructor, you don’t need the slashes, you are maybe confusing it with the syntax ofRegExpliterals.\Wcharacter class.The following will work:
The
RegExpconstructor accepts a string containing the pattern, note that you should double escape the slash, in order to get a single slash and a W ("\W") in the string.Or you could simply use the literal notation:
Recommended read: