0

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?

11
  • 1
    What happened to your other question? I took the trouble to answer it and now it's gone. Also, is it deliberate that the <% ... %> 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? Commented Jan 25, 2012 at 4:24
  • 1
    Care to tell us what is the reason for that? Commented Jan 25, 2012 at 4:25
  • @nnnnnn it was voted down 5 times, had to delete it. yes it is deliberate, and its JST. its for doing some stuff in node.js Commented Jan 25, 2012 at 4:27
  • You don't have to delete things just because they get downvoted. You could've edited the other question. Also, why is the <table> element and the closing } from the for missing from the desired output? Commented Jan 25, 2012 at 4:33
  • @nnnnnn thank you for your answer, but its was badly written,so im sorry for the deletion Commented Jan 25, 2012 at 4:35

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.