On Tuesday 05 August 2003 17:32, Xavier Noria wrote:

> Yet another regex solution:
>
>     % ruby -e 'puts "456778904".gsub(/(.)(?=.{3}+$)/, %q(\1,))'
>     456,778,904
>
> -- fxn
>
>     .gsub(/(\d)(?=\d{3}+$)/, '\1,')

That spurious line at the end uses a regex that works for negative 
numbers as well.

-- fxn