阅读背景:

Hackerrank - Smart IDE Extract Comments

来源:互联网 



 

用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



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: