I have a string that dynamically comes from another document as follows;
"<!DOCTYPE html>
<html dir="ltr"><head><title>Preview</title></head>
<body>
<p>test</p>
<p><img alt="" height="299" src="http://172.0.0.1/Administration/YDImages/cap.JPG" width="696"></p>
</body>
</html>"
I use this string as follows;
var html = stringAbove;
var reg = html.match(/<body[^>]*>(.*)<\/body>/);
var newDocument = "<p>My new Texts and styles</p>"; //replace inside body with my new code
var newer = html.replace(reg[1],newDocument);
doc.write(newer);
I've discovered that html.match
returns null
if the string inside html variable as it is above, while debugging to see how could I make this regex work on developer tools, I've changed starting and ending double quotes of the string to single quotes, so it worked. Then I changed all double quotes to single quotes and try regex function but it doesn't work. Please, help me to get this regex work properly.