in reply to Regex to replace consecutive tokens
Yet another way to do it:
$s = join(",", map {$_ ne '' ? $_ : '0'} split /,/,$s,-1);
Update: Added '-1' to split to ensure we don't lose trailing commas, as hdb mentions. (Also corrected typo $t-->$s.)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to replace consecutive tokens
by hdb (Monsignor) on Oct 18, 2013 at 13:24 UTC | |
by choroba (Cardinal) on Oct 18, 2013 at 13:44 UTC |