早上,我想捕获冒号前的字符串:,然后比较冒号后的字符串,并删除与冒号前的值相等的值。
例如:
aaa:aaa-bbb-ccc输出:
aaa others:bbb,ccc下面是我的代码
$string = "aaa:aaa-bbb-ccc";
$first =~ /(:.*\)/; //get aaa before the colon
$others =$string=~ s/$first//; remove the same values after colon你能帮帮我吗??谢谢。。
发布于 2017-09-25 10:35:33
这是可行的:
use strict;
use warnings;
my $s='aaa:aaa-bbb-ccc';
if ($s=~/^([^:]+):/) {
my $first=$1;
$s=~s/\Q$1\E://;
print "$first others:" . join ',', grep { $_ ne $first } split '-', $s;
}
# aaa others:bbb,ccchttps://stackoverflow.com/questions/46396523
复制相似问题