如何从使用Perl文件中剥离多行C注释? [英] How can I strip multiline C comments from a file using Perl?
本文介绍了如何从使用Perl文件中剥离多行C注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以让我与常规的前pression脱光多行注释和单行注释在一个文件?
Can anyone get me with the regular expression to strip multiline comments and single line comments in a file?
的例如:的
" WHOLE "/*...*/" HAS TO BE STRIPED OFF....."
1. /* comment */
2. /* comment1 */ code /* comment2 */ #both /*comment1*/ and /*comment2*/
#has to striped off and rest should
#remain.
3. /*.........
.........
.........
......... */
我真的AP preciate你如果妳做这方面的需求....在此先感谢。
i realy appreciate you if u do this need.... thanks in advance.
推荐答案
包括测试:
use strict;
use warnings;
use Test::More qw(no_plan);
sub strip_comments {
my $string=shift;
$string =~ s#/\*.*?\*/##sg; #strip multiline C comments
return $string;
}
is(strip_comments('a/* comment1 */ code /* comment2 */b'),'a code b');
is(strip_comments('a/* comment1 /* comment2 */b'),'ab');
is(strip_comments("a/* comment1\n\ncomment */ code /* comment2 */b"),'a code b');
这篇关于如何从使用Perl文件中剥离多行C注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文