From: Robert Klemme Date: 2009-08-07T00:43:30+09:00 Subject: Re: remove commas from string 2009/8/6 Jason Lillywhite : > Steve Ross wrote: > >> Why so complex? Perhaps: >> >>  >> s.gsub(/\b(\d+),(\d+)\b/, '\1\2') >> => "B747-400, 8357 miles, 561 mph, 56000 lbs." >> >> Is there a corner case I'm missing here? > > So I think I would like to try a non-block option but this code above > misses the second comma if I have say 12,134,650 lbs instead of 56,000 > lbs in my string. > > It looks like I need Ruby 1.9 to do this: s.gsub(/(?<=\d),(?=\d{3})/, > '') > > If I have not yet installed Ruby 1.9, what would be a good non-block > regex that is more robust? s.gsub(/(\d),(?=\d{3})/,'\\1') Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/