I have this var
var x = "<div class=\\\"abcdef\\\">";
Which is
<div class=\"abcdef\">
But I need
<div class="abcdef">
How can I “unescape” this var to remove all escaping characters?
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.
You can replace a backslash followed by a quote with just a quote via a regular expression and the
String#replacefunction:Note that the regex just looks for one backslash; there are two in the literal because you have to escape backslashes in regular expression literals with a backslash (just like in a string literal).
The
gat the end of the regex tellsreplaceto work throughout the string (“global”); otherwise, it would replace only the first match.