title: Removing C/C++ style comments using boost::regex
body: <p>I'm attempting to remove C and C++ style comments from a string using a regular expression.  I have found one for Perl that seems to do both:</p>
  
  <p><code>s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;</code></p>
  
  <p>But I am unsure as to how to use this with a <code>boost::regex</code> code block, or what I need to do to transform it into a regular expression accepted by <code>boost::regex</code>.</p>
  
  <p>FYI: I found the regular expression here: <a href="http://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file?" rel="nofollow">perlfaq6</a> and it seems to cover any case I would need.</p>
  
  <p>I would prefer not to use <code>boost::spirit::qi</code> to do this, as it would add a great deal of time to compilation for the project.</p>
  
  <p>EDIT: </p>
  
  <pre><code>std::string input = "hello /* world */ world";
  
  boost::regex reg("(/\\*([^*]|(\\*+[^*/]))*\\*+/)|(//.*)");
  
  input = boost::regex_replace(input, reg, "");
  </code></pre>
  
  <p>So the shorter regex does indeed work, however the longer one does not.</p>