in reply to Insert colons into a MAC address

s/..(?=.)\K/:/g;

See 944097.

Replies are listed 'Best First'.
Re^2: Insert colons into a MAC address
by AnomalousMonk (Archbishop) on Jan 13, 2012 at 16:12 UTC

    Without nasty look-aheadses:

    >perl -wMstrict -le "my $ma = '525400eb8b36'; $ma =~ s/..\K\B/:/g; print qq{'$ma'}; " '52:54:00:eb:8b:36'
      >perl -wMstrict -le 'my $ma="525400eb8b36"; $ma =~ s/..\K\B/:/g; > print $ma; ' Unrecognized escape \K passed through at -e line 1. 525400eb8b36 >
      Old Perl Version syndrome, I guess.
        Old Perl Version ...

        Indeed. The  \K special escape was introduced with 5.10. The following works pre-5.10, but we're back to a look-back. Oh, well...

        >perl -wMstrict -le "print $]; my $ma = '525400eb8b36'; $ma =~ s{ (?<= \G ..) \B }{:}xmsg; print qq{'$ma'}; " 5.008009 '52:54:00:eb:8b:36'