I’m probably doing something very stupid but I can’t get following regexp to work in Javascript:
pathCode.replace(new RegExp("\/\/.*$","g"), "");
I want to remove // plus all after the 2 slashes.
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.
Seems to work for me:
Also note that the regular-expression literal
/\/\/.*$/gis equivalent to the regular-expression generated by your use of theRegExpobject. In this case, using the literal is less verbose and might be preferable.Are you reassigning the return value of
replaceintopathCode?replacedoesn’t modify the string object that it works on. Instead, it returns a value.