I gave a poor description in my prev. question on what i want to do,
so here's another shot:
i have this string:
"<HTML>\n"+
"<P><BODY>\n"+
"<%for(var i=0;i<5;i++){%>\n"+
"<%response.body+=i;%><br/><br/>\n"+
"<%}%>\n"+
"<table border=’1’ width="100%">\n"+
"</BODY></P>\n"+
"</HTML>\n";
and i want to manipulate this into the following:
"response.body+=<HTML>;\n"+
"response.body+=<P><BODY>;\n"+
"for(var i=0;i<5;i++){\n"+
"response.body+=i;response.body+=<br/><br/>;\n"+
"response.body+=</BODY></P>;\n"+
"response.body+=</HTML>;\n";
meaning; adding to anything not in "<% some code %>"
this: "response.body+=" and ";".
how can it be done?
asked Jan 25, 2012 at 4:19
Itzik984
17k29 gold badges74 silver badges110 bronze badges
1 Answer 1
My motivation to provide a complete answer is low given that I already answered your other question and now it's been deleted, but you could try something like the following:
yourString.replace(/'/g,"\\'")
.replace(/(<[^%>]+>)/g,"response.body+='1ドル';")
.replace(/<%|%>/g,"");
I'm assuming you intended to have the html tags in single quotes as in your other question.
answered Jan 25, 2012 at 4:30
nnnnnn
150k30 gold badges210 silver badges247 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
<% ... %>tags are missing from your desired result? And speaking of<% ... %>- such tags imply JSP or ASP server-side code, so why do you have that in a JavaScript string?<table>element and the closing}from theformissing from the desired output?