Q: How to replace \" with " using regex? I have an API that returns an HTML string but it has some extra characters in the API and I want to replace that with something else.
<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0\">

I want to replace \" with  " using that using replace so that it becomes
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0">

What is the regex string.replace() for doing the above task?

A: So you have to escape the \ with another \
yourstring.replace(/\\"/, '"')


A: You can simply use this without RegEx
<?php
$a = "<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0\">";
$b = str_replace('\"', '"', $a);
var_dump($b);


A: use the \\ into your regexp


var text = '<meta name=\"viewport\" content=\"initial-scale=1.0, maximum-scale=1.0\">';

var result  = text.replace(/\\"/g, '"');

console.log(result);


