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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs