Let’s say that I have like this: "\\n", I need to convert it to a string like if the interpreter would do it: \n.
A simple replace like this wouldn’t work:
function aaa(s){
return s.replace(/\\n/gm,'\n').replace(/\\\\/gm,'\\');
}
I need this behaviour:
"Line 1\nLine 2"=>Line 1<Line break>Line 2"Line 1\\nLine 1"=>Line 1\nLine1
The simplest, and most evil, solution, is to write
return eval(s).Do not do that.
Instead, you need to make a single
replacecall with a match evaluator, like this:(Tested)