用perl来处理正则表达式比较方法,代码很少。
my $str = "";
while(<>) {
$str .= $_;
}
my $out = "";
while($str =~ /(\/\*.*?\*\/|\/\/.*?\n)/gs) {
my $comment =
用perl来处理正则表达式比较方法,代码很少。
my $str = "";
while(<>) {
$str .= $_;
}
my $out = "";
while($str =~ /(\/\*.*?\*\/|\/\/.*?\n)/gs) {
my $comment = $1;
if($comment =~ /^\/\*/g) {
$comment =~ s/\n[^\S\n]*/\n/g;
}
if(($out eq "") || ($out =~ /\n$/)) {
$out .= $comment;
} else {
$out .= "\n$comment";
}
}
print $out;
转载自yuanhsh.iteye.com/blog/2200519;
if($comment =~ /^\/\*/g) {
$comment =~ s/\n[^\S\n]*/\n/g;
}
if(($out eq "") || ($out =~ /\n$/)) {
$out .= $comment;
} else {
$out .= "\n$comment";
}
}
print $out;my $str = "";
w