# Re: remove commas from string

**URL:** <https://www.ruby-forum.com/t/re-remove-commas-from-string/173223>\
**Category:** Ruby\
**Created:** [August 5, 2009, 8:15am UTC](https://www.ruby-forum.com/t/re-remove-commas-from-string/173223 "2009-08-05T08:15:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 5, 2009, 8:15am UTC](https://www.ruby-forum.com/t/re-remove-commas-from-string/173223/1 "2009-08-05T08:15:39Z")

</div>

> 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
