in reply to A regex question...

I think that a couple of small mods to your own solution make it very clear and readable. First, if you know they are digits, no need to specify that. Second, use paired delimiters and lay it out over two lines

$s = s[(.{5}) (.{5}) (.{5}) (.{5}) (.{5}) (.{5})] [$1-$2-$3<br />$4-$5-$6]x;

If the /x modifier also operated in the replacement, I would line the bits up vertically too.

The only other change I might make is if the regex was used in more than one place, I would probably compile it with qr// and give it a meaningful name.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re^2: A regex question... (/x for right side of s///)
by Aristotle (Chancellor) on May 07, 2003 at 00:07 UTC
    If the /x modifier also operated in the replacement, I would line the bits up vertically too.
    You could add /e and build a string with dot concatenations.

    Makeshifts last the longest.