From: Nick Brown Date: 2009-08-06T22:32:50+09:00 Subject: Re: remove commas from string Ruby has the neat ability to pass a block to gsub. This can be a more versatile solution than using backreferences. It also allows Jason to use his original, straight-forward regex. The matched string is passed to the block, and whatever the block evaluates to is used as the replacement string. Check it out: irb(main):012:0> s => "B747-400, 8357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, turbofans, 56,000 lbs." irb(main):013:0> s.gsub(/\d+,\d+/) { |subs| subs.gsub(',', '') } => "B747-400, 8357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, turbofans, 56000 lbs." -- Posted via http://www.ruby-forum.com/.