2017-04-03 52 views
-1

我想串perl脚本将字符串EXP501.1-01.0转换为EXP501_01

EXP501.1-01.0

EXP501_01

转换

这意味着-01,-02,-03 ...是增量式的,我想追加第二个字符串(将根据第一个字符串进行分析)的_旁边的第一个字符串中的相同数字。

+0

我改变了一些文本格式,突出显示了一些数字,并添加了两个相关的标签。 – zx485

回答

1
my $string = "EXP501.1-01.0"; 
    $short = substr($string, 0, -7); 
    $new = substr($string,8,-2); 
    my $str = $short . $new; 
    $str =~ s/ - /_/g; # Replace all " - " with "_" 
    $str =~ s/[^A-Za-z0-9]/_/g; # Replace all non-alphanumericals with "_" 

    print $str . "\n"; 
+0

其工作:)谢谢abhi –

+1

@ManjunathS:就这样,如果你发现答案对你有帮助,接受它会被认为是礼貌的。 – zx485