title: Strip comments from javascript file
body: <p>I'm trying to construct a regular expression to strip all comments from javascript code, both single-line (//...) and multiline (/*..*/). This is what I've come up with:</p>
  
  <pre><code>/\"[^\"]*\"|'[^']*'|(\/\/.*$|\/\*[^\*]*\*\/)/mg
  </code></pre>
  
  <p>Description: As you can see it searches also for string literals. This is because string literals can contain content that otherwise could match the comment patterns (for example: location.href = "<a href="http://www.domain.com" rel="nofollow">http://www.domain.com</a>"; will match as single line comment). So I put the string literal patterns first among the alternatives patterns. Following this are the two patterns which are intended to catch single line comments and multiline comments, respectively. These are enclosed in the same capturing group, so that I can use string.replace(pattern, "") to remove the comments.</p>
  
  <p>I've tested the expression with a couple of js-files and it seems to be working. <strong>My question is if there are other patterns that I should be looking for or if there are any other things to consider</strong> (for example if there is limited support for regular expressions or alternative implementation in some browsers that need to be considered).</p>