我想串perl脚本将字符串EXP501.1-01.0转换为EXP501_01
EXP501.1-01.0
到
转换EXP501_01
这意味着-01
,-02
,-03
...是增量式的,我想追加第二个字符串(将根据第一个字符串进行分析)的_
旁边的第一个字符串中的相同数字。
我想串perl脚本将字符串EXP501.1-01.0转换为EXP501_01
EXP501.1-01.0
到
转换EXP501_01
这意味着-01
,-02
,-03
...是增量式的,我想追加第二个字符串(将根据第一个字符串进行分析)的_
旁边的第一个字符串中的相同数字。
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";
其工作:)谢谢abhi –
@ManjunathS:就这样,如果你发现答案对你有帮助,接受它会被认为是礼貌的。 – zx485
我改变了一些文本格式,突出显示了一些数字,并添加了两个相关的标签。 – zx485