From: Xavier Noria Date: 2003-08-06T00:48:51+09:00 Subject: Re: format number with comma separators? 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