title: How can I replace specific JavaScript comments with a regular expression?
body: <p>I have task where I have to open many files, search for <code>//@public object</code> pattern, and if it has no matches, remove all JavaScript comments inside that file that do not have <code>//@public doc</code> before it.</p>
  
  <p>For example, there might be something similar to this:</p>
  
  <pre><code>//@public doc
      /**
       * @function
       * checks for specific conditions
       * specific variables
       */
  </code></pre>
  
  <p>and that remains as is. But every other JavaScript comment needs to be removed.</p>
  
  <p>What would be regular expression for it, and how to achieve that?</p>
  
  <p>Thank you in advance.</p>
  
  <p>In the meanwhile, I came up to do following solution</p>
  
  <pre><code>    &lt;fileset id="jsmvcdoc.fileset" dir="${doctempfolder}" includes="**/*.js"&gt;
          &lt;not&gt;
           &lt;contains text="//@public object" casesensitive="no"/&gt;
          &lt;/not&gt;
      &lt;/fileset&gt;
  
     &lt;!-- JS Comments --&gt;
     &lt;replaceregexp match="(?!doc. +)/\*.+?\*/" replace="" flags="gs" byline="false"&gt;
          &lt;fileset refid="jsmvcdoc.fileset"/&gt;
     &lt;/replaceregexp&gt;
  </code></pre>
  
  <p>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</p>
  
  <p>Solved it this way:</p>
  
  <pre><code>&lt;!-- strip out js comments not preceeded by //@public doc --&gt;
    &lt;replaceregexp match="(?&amp;lt;!//@public doc\x0D\x0A    )/\*.+?\*/" replace="" flags="gs" byline="false"&gt;
          &lt;fileset refid="jsmvcdoc.fileset"/&gt;
    &lt;/replaceregexp&gt;
  </code></pre>