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:
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;
But I am unsure as to how to use this with a boost::regex
code block, or what I need to do to transform it into a regular expression accepted by boost::regex
.
FYI: I found the regular expression here: perlfaq6 and it seems to cover any case I would need.
I would prefer not to use boost::spirit::qi
to do this, as it would add a great deal of time to compilation for the project.
EDIT:
std::string input = "hello /* world */ world";
boost::regex reg("(/\\*([^*]|(\\*+[^*/]))*\\*+/)|(//.*)");
input = boost::regex_replace(input, reg, "");
So the shorter regex does indeed work, however the longer one does not.