giving:use strict; my $string = '|xx-xxx-xxxxx-xxx x/xx|xx-xxxx-xxx-xx-xxxx-xx-xx|'; print "$string\n"; $string =~ s/\|//; # gets rid of the first pipe $string =~ s/\|/,/g; # replaces all other pipes by commas print "$string\n"; my @chunks = split '-', $string; $string = join( '-', @chunks[ 0 .. 3 ] ) . ',' . join( ',', @chunks[ 4 .. $#chunks ] ); print "$string\n";
Please note that it appears you also replace a space by a comma in your example.|xx-xxx-xxxxx-xxx x/xx|xx-xxxx-xxx-xx-xxxx-xx-xx| xx-xxx-xxxxx-xxx x/xx,xx-xxxx-xxx-xx-xxxx-xx-xx, xx-xxx-xxxxx-xxx x/xx,xx,xxxx,xxx,xx,xxxx,xx,xx,
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: REGEX detailed character replace
by CountZero
in thread REGEX detailed character replace
by pjc955
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |