in reply to Regex split string into n-length
$string =~ s/(\w\w\w)/$1-/g;
UPDATE: As Ken pointed out correctly, this solution is wrong as it puts an additional - in a case like '123456'.
So, putting a negative lookahead to the pattern should do the trick:
$string =~ s/(\w\w\w)(?!$)/$1-/g;
McA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex split string into n-length (\K 5.010)
by Anonymous Monk on Sep 10, 2013 at 07:37 UTC | |
by kcott (Archbishop) on Sep 10, 2013 at 07:52 UTC | |
by McA (Priest) on Sep 10, 2013 at 07:57 UTC | |
by McA (Priest) on Sep 10, 2013 at 07:52 UTC |