From: headspin@... Date: 2009-08-05T15:15:01+09:00 Subject: Re: remove commas from string > s.gsub(/\d+(,)\d+/, "") > It turns out that my regex removes the entire number, not just the comma. Er, yes, you asking to replace \d+(,)\d+ with nothing, that's exactly what it does... Try something like this (typing from memory, untested): s.gsub(/(\d),(\d\d\d)/, "\1\2") -- Didier ------Original Message------ From: Jason Lillywhite Sender: jason.lillywhite@gmail.com To: ruby-talk ML ReplyTo: ruby-talk@ruby-lang.org Sent: Aug 5, 2009 14:01 Subject: remove commas from string I have following string: s = "B747-400, 8,357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, 56,000 lbs." I want to remove the comma only from the numbers (8,357 miles and 56,000 lbs) separating the thousands. I want the string to read as follows: "B747-400, 8357 miles, 561 mph, 4 Pratt & Whitney PW 4056 turbofans, 56000 lbs." I thought this following regex would do the trick because it successfully isolated the right commas in rubular.com s.gsub(/\d+(,)\d+/, "") It turns out that my regex removes the entire number, not just the comma. Am I wrong in saying that my regex searches for 1 or more numbers surrounding a comma and replaces just the comma with ""? Thank you. -- Posted via http://www.ruby-forum.com/. Sent from my BlackBerry® smartphone