[svn:perlfaq] r12516 - perlfaq/trunk

[email protected] Thu, 19 Feb 2009 14:21:50 -0800 (PST)
Newsgroups perl.cvs.perlfaq
Message-ID <[email protected]>
Author: comdog
Date: Thu Feb 19 14:21:49 2009
New Revision: 12516

Modified:
   perlfaq/trunk/perlfaq6.pod

Log:
* perlfaq6: How do I use a regular expression to strip C style comments from a file?
	+ [email protected] modified the C++ comment stripper to 
	handle continuation lines.


Modified: perlfaq/trunk/perlfaq6.pod
==============================================================================
--- perlfaq/trunk/perlfaq6.pod	(original)
+++ perlfaq/trunk/perlfaq6.pod	Thu Feb 19 14:21:49 2009
@@ -493,10 +493,10 @@
        )
      }{defined $2 ? $2 : ""}gxse;
 
-A slight modification also removes C++ comments, as long as they are not
-spread over multiple lines using a continuation character):
+A slight modification also removes C++ comments, possibly spanning multiple lines
+using a continuation character:
 
-	s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
+ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;
 
 =head2 Can I use Perl regular expressions to match balanced text?
 X<regex, matching balanced test> X<regexp, matching balanced test>