# Match all occurance of double quotes in a string

**URL:** <https://www.ruby-forum.com/t/match-all-occurance-of-double-quotes-in-a-string/65601>\
**Category:** Ruby\
**Created:** [August 19, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/match-all-occurance-of-double-quotes-in-a-string/65601 "2006-08-19T18:06:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [August 19, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/match-all-occurance-of-double-quotes-in-a-string/65601/1 "2006-08-19T18:06:08Z")

</div>

I have a string something like this…  
“Now is the time for all good men to blah, blah…” - Origin unknown

I want to convert it to this…  
Now is the time for all good men to blah, blah… - Origin  
unknown

With the first double quote converted to “" and the second to "”.  
The occurance of the 1st double quote may or may not be at the beginning  
of the string.

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [August 19, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/match-all-occurance-of-double-quotes-in-a-string/65601/2 "2006-08-19T18:13:10Z")

</div>

Patrick S. wrote:

> 

Rather simplistic, but should work:

string.sub(/"([^"]\*)"/, ‘\1’)

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [August 19, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/match-all-occurance-of-double-quotes-in-a-string/65601/3 "2006-08-19T18:17:41Z")

</div>

Alex Y. wrote:

> Patrick S. wrote:
> 
> > 
> 
> Rather simplistic, but should work:
> 
> string.sub(/"([^"]\*)"/, ‘\1’)

I like simple, thanks!
