I have task where I have to open many files, search for //@public object pattern, and if it has no matches, remove all JavaScript comments inside that file that do not have //@public doc before it.
For example, there might be something similar to this:
//@public doc
/**
* @function
* checks for specific conditions
* specific variables
*/
and that remains as is. But every other JavaScript comment needs to be removed.
What would be regular expression for it, and how to achieve that?
Thank you in advance.
In the meanwhile, I came up to do following solution
<fileset id="jsmvcdoc.fileset" dir="${doctempfolder}" includes="**/*.js">
<not>
<contains text="//@public object" casesensitive="no"/>
</not>
</fileset>
<!-- JS Comments -->
<replaceregexp match="(?!doc. +)/\*.+?\*/" replace="" flags="gs" byline="false">
<fileset refid="jsmvcdoc.fileset"/>
</replaceregexp>
Which filters fileset including only those file that do not contain //@public object, but I dont have idea how to make regexp which will strip all comments except those which are preceeded by line //@public doc
Solved it this way:
<!-- strip out js comments not preceeded by //@public doc -->
<replaceregexp match="(?<!//@public doc\x0D\x0A )/\*.+?\*/" replace="" flags="gs" byline="false">
<fileset refid="jsmvcdoc.fileset"/>
</replaceregexp>
//@public object, and if that text is not found in the file, you need to remove a) everything that isn’t a JavaScript comment, and b) every JavaScript comment that is not immediately preceded by the text//@public doc.