in reply to Use Regular Expression to add spaces to a string
Just to show another way that doesn't use regular expressions, you could use substr with a negative offset to work back from the end of the string using a loop statement modifier. Not as clear to the eye as BrowserUk's regex solution but hopefully of interest.
knoppix@Microknoppix:~$ perl -E ' > $str = q{abcdefghi}; > substr $str, -( $_ + 3 * ( $_ + 1 ) ), 0, ( q{-}, q{ } )[ $_ ] > for 0 .. 1; > say $str;' abc def-ghi knoppix@Microknoppix:~$
Cheers,
JohnGG
|
|---|