From: Gregory Millam Date: 2003-12-09T05:43:57+09:00 Subject: Re: format money Received: Tue, 9 Dec 2003 05:39:27 +0900 And lo Peter wrote: > > # Here's my try: > > > > balance.to_s.reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse > > > > examples: > > irb(main):007:0> "123456789".reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse > > => "123,456,789" > > irb(main):008:0> "1234567890".reverse.gsub(/(\d{3})(?=\d)/,'\1,').reverse > > => "1,234,567,890" > > > > (?=\d) is a lookahead assertion that checks to see if there's a digit > > ahead of the current pattern without capturing it (which is the > > important thing). > > Apparently I hid my try pretty well in my reply :-) > > Peter *hits forehead* Because of the ">" in irb(main):...:..>, my mua displays it as a comment. *continues to hit forehead* - Greg 'blind' Millam