javascript - Replace JS comments in eclipse -


i'm working on old project we're using jsp in front-end. actual job remove js-comments (//) , replace them jsp-comments (<%-- --%>) in .jsp-files reduce traffic. ide eclipse, i'm using search , replace on multiple files regex (ctrl+h).

note

i've removed /* */ comments in files.

for example code find in jsp-file:

<script type="text/javascript"> <!--     function submitsave() {         // coment in js         if (doubleclick()) { return; }          document.benutzerrollenfunktionenform.action = '<%=request.getcontextpath()%>/administration/benutzerrollenfunktionenbearbeiten.do';          <% if (request.getattribute("methode") != null && request.getattribute("methode").tostring().trim().equals("benutzerspeichern")) { //%>             document.benutzerrollenfunktionenform.method.value = 'benutzerspeichern';         <% } else if (request.getattribute("methode") != null && request.getattribute("methode").tostring().trim().equals("benutzerneuanmeldungspeichern")) { %>             document.benutzerrollenfunktionenform.method.value = 'benutzerneuanmeldungspeichern';         <% } // end if %>     } //--> </script> 

as can see, there comments inside jsp-tags, can't search // , remove them.

i can match comments aren't in oneliner-jsp-tag regex:

^((?:(?!<%).)*)(\/\/)((?:(?!-->|%>).)*)$ 

note

--> preventing match //--> because isn't normal comment needs remain.

but there code this:

<%   java code   //comment %> 

does have solution match comments in js replace them with-jsp comments?

edit

unfortunately can't hand, because there more 1000 files , more 1000 comments...

write program read file in line line. traverse lines, turn flag true when encounter . then, when encounter // , flag false, replace // . when flag true, don't that.


Comments