# Gsub jocks - Do you have an example that does this?

**URL:** <https://www.ruby-forum.com/t/gsub-jocks-do-you-have-an-example-that-does-this/147793>\
**Category:** Rails\
**Created:** [September 5, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/gsub-jocks-do-you-have-an-example-that-does-this/147793 "2008-09-05T15:15:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/gsub-jocks-do-you-have-an-example-that-does-this/147793/1 "2008-09-05T15:15:07Z")

</div>

I know I’ve been lazy not learning RegExp and gsub but I simply never  
use it except for this one time.  
I’ll be importing .csv records and sometimes they’ll be dirty with  
characters like ( # " ) and I’d like to change these to a space.  
I would be grateful for a simple example?  
Thank you,  
Kathleen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 5, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/gsub-jocks-do-you-have-an-example-that-does-this/147793/2 "2008-09-05T15:36:53Z")

</div>

On Fri, Sep 5, 2008 at 9:14 AM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> I know I’ve been lazy not learning RegExp and gsub but I simply never  
> use it except for this one time.  
> I’ll be importing .csv records and sometimes they’ll be dirty with  
> characters like ( # " ) and I’d like to change these to a space.  
> I would be grateful for a simple example?  
> Thank you,  
> Kathleen

line.gsub!(/[#"]/,’ ')

the start / and end / define the regex. [#"] means 'match any one of the  
following: # and " ’

the gsub-bang (gsub!) method will change the contents of the line  
variable.  
If you’re more cautious do clean\_line = line.gsub(…)

–  
Tim
