regex - Incrementing integers in particular positions in perl -


i have string this:

1,2,4 0:5 1:10 3:14 

which want convert

1,2,4 1:5 2:10 4:14 

only numbers before ":" have incremented 1.

i have tried:

perl -w -e '$s="1,2,4 0:5 1:10 3:14";  $s =~ s/([0-9]*):/print(($1+1).":")/ge;  print("$s\n");' 

which strangely returns

1:2:4:1,2,4 15 110 114 

is there easy way of achieving objective?

you close enough, has match @ least 1 digit, followed :, , substitution part has return desired result, not print it.

my $s = "1,2,4 0:5 1:10 3:14";  $s =~ s/([0-9]+) (?=:)/ $1+1 /xge;  print $s, "\n"; 

Comments