# gsub fail

**URL:** <https://discuss.rubyonrails.org/t/gsub-fail/49589>\
**Category:** rubyonrails-talk\
**Created:** [February 22, 2010, 8:02pm UTC](https://discuss.rubyonrails.org/t/gsub-fail/49589 "2010-02-22T20:02:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 22, 2010, 8:02pm UTC](https://discuss.rubyonrails.org/t/gsub-fail/49589/1 "2010-02-22T20:02:11Z")

</div>

Hi guys: I'm trying go through a table, read a field, escape out all the single quotes in there, and write it back again. For some reason my gsub, even though by all accounts looks right, doesn't seem to be working. Here is my code:

... y.text.gsub("'","\\\\'") thesql = "text = '"+y.text+"'" Capture.update\_all( thesql, "id = "+y.id.to\_s ) ...

Constantly breaks on an entry that includes "It's going up on..."

right at the ' in It's.

Any ideas? I even wrote a loop to recurse through the string and make sure that I was a really a single quote (39)

Thanks...Chris

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 22, 2010, 8:39pm UTC](https://discuss.rubyonrails.org/t/gsub-fail/49589/2 "2010-02-22T20:39:59Z")

</div>

> y.text.gsub("'","\\\\'")

Nothing is changing here. You need to add a bang.

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 22, 2010, 9:37pm UTC](https://discuss.rubyonrails.org/t/gsub-fail/49589/3 "2010-02-22T21:37:57Z")

</div>

Sharagoz -- wrote:

> > y.text.gsub("'","\\\\'")
> 
> Nothing is changing here. You need to add a bang.

Doh! Thanks. I was using the same code elsewhere but without the bang.
