我有一个文件,其格式为'21pro_ABCD_EDG_10800_48052_2 0.0'
如何用a,(逗号)替换_ [0-9],以便我可以得到输出
21pro_ABCD_EDG,10800,48052,2,0.0
要更换_[0-9]用,你能做到这样:
$s =~ s/_([0-9])/,$1/g
#the same without capturing groups
$s =~ s/_(?=[0-9])/,/g;
Run Code Online (Sandbox Code Playgroud)
编辑:
要获得额外的逗号,2您可以执行此操作:
#This puts a , before all whitespace.
$s =~ s/_(?=[0-9])|(?=\s)/,/g;
#This one puts a , between [0-9] and any whitespace
$s =~ s/_(?=[0-9])|(?<=[0-9])(?=\s)/,/g;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
570 次 |
| 最近记录: |