great regex! me too have forgoten about the look-ahead assertion :(
my function that does number beautifying has no less than 8 lines :((
still.. there's a little problem when handling floats:
the digits after the dot shouldn't be 'beautified' :(
.. i tried to enhance a little your line but the problem still remains because of the fixed-width look-behind:
$number =~ s/(?<!\.\d)(\d)(?=(\d{3})+(\D|$))/$1,/g;
(this example works for numbers with 5 digits after the dot... variations may me done by modifying the 'quantity' of \d from the look-behind assertion)
couldn't think at anything better now.. maybe you have another bright idea for this too o=)
so, after inserting your wizcraft, my lame tool looks something like this:
$number =~ s/(\d+)(\.\d+)?/bea_int($1).$2/eg; sub bea_int { my $kk = $_[0]; $kk =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; return $kk; }
--
AltBlue... w8ing 4 a better solution o=Q
In reply to RE: RE: regexp for adding commas to a number
by AltBlue
in thread regexp for adding commas to a number
by Kozz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |