in reply to REGEX detailed character replace
How do i change all dashes to commas except the first three
ormy $c = 0; s/-/$c++ < 3 ? '-' : ','/eg;
orlocal our $c = 0; s/-(?(?{ $c++ < 3 })(?!))/,/g;
or# As is, assumes at least 3 commas are found. my ($pre, $post) = /^((?:[^-]-){3})(.*)/s; $post =~ s/-/,/g; $_ = "$pre$post";
# As is, assumes at least 4 commas are found. my @parts = split(/-/, $_, -1); $_ = join(',', join('-', @parts[0..3]), @parts[4..$#parts]);
is there a way to do the first question along with removing white spaces, replacing pipes with commas (except first) all in one line
Yup
Update: Fixed rushed code as per reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: REGEX detailed character replace
by Anonymous Monk on Nov 12, 2008 at 09:14 UTC | |
by perlsaran (Sexton) on Nov 13, 2008 at 06:52 UTC | |
by ikegami (Patriarch) on Nov 13, 2008 at 16:05 UTC |