Escaping '“' with regular double quotes using Ruby regex

Posted by DavidP6 on Stack Overflow See other posts from Stack Overflow or by DavidP6
Published on 2010-05-26T03:19:53Z Indexed on 2010/05/26 3:21 UTC
Read the original article Hit count: 543

Filed under:
|
|

I have text that has these fancy double quotes: '“' and I would like to replace them with regular double quotes using Ruby gsub and regex. Here's an example and what I have so far:

sentence = 'This is a quote, “Hey guys!”'  

I couldn't figure out how to escape double quotes so I tried using 34.chr:
sentence.gsub("“",34.chr).  This gets me close but leaves a back slash in front of the double quote:

sentence.gsub("“",34.chr) => 'This is a quote, \"Hey guys!”' 

© Stack Overflow or respective owner

Related posts about ruby

Related posts about regex