Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 803661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:47:43+00:00 2026-05-14T23:47:43+00:00

I have text that has these fancy double quotes: ” and I would like

  • 0

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!”' 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:47:43+00:00Added an answer on May 14, 2026 at 11:47 pm

    The backslashes are only showing up in irb due to the way it prints out the result of a statement. If you instead pass the gsubed string to another method such as puts, you’ll see the “real” representation after escape sequences are translated.

    1.9.0 > sentence = 'This is a quote, “Hey guys!”'  
     => "This is a quote, \342\200\234Hey guys!\342\200\235" 
    1.9.0 > sentence.gsub('“', "'")
     => "This is a quote, 'Hey guys!\342\200\235" 
    1.9.0 > puts sentence.gsub('“', "'")  
    This is a quote, 'Hey guys!”
     => nil
    

    Note also that after the output of puts, we see => nil indicating that the call to puts returned nil.

    You probably noticed that the funny quote is still on the end of the output to puts: this is because the quotes are two different escape sequences, and we only named one. But we can take care of that with a regex in gsub:

    1.9.0 > puts sentence.gsub(/(“|”)/, 34.chr)
    This is a quote, "Hey guys!"
     => nil
    

    Also, in many cases you can swap single quotes and double quotes in Ruby strings — double quotes perform expansion while single quotes do not. Here are a couple ways you can get a string containing just a double quote:

    1.9.0 > '"' == 34.chr
     => true 
    1.9.0 > %q{"} == 34.chr
     => true 
    1.9.0 > "\"" == 34.chr
     => true 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that I want to edit using Java. It has
I have a text file that has some invalid byte sequences. Emacs renders these
I have some text that has HTML hyper-links in it. I want to remove
I have a text string that has been doctored to be web safe URLs
I have a text file that has item numbers in it (one per line).
I currently have a text file that has the following: 1 Commercial & Enterprise
Let's say I have some original text: here is some text that has a
I have a C# form that has a text box that needs to constantly
I have an xml that has text within word elements e.g <word>Police</word> <word>confirmed</word> <word>they
We have an application that has one or more text console windows that all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.