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.
|
|---|
| 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 |