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

  • Home
  • SEARCH
  • 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 9087189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:15+00:00 2026-06-16T21:39:15+00:00

I’m doing some text processing with Ruby. For some text I’m working with: single

  • 0

I’m doing some text processing with Ruby.

For some text I’m working with: single quotes should never be outside of double quotes. So, I’d like to craft a RegEx which matches single-quoted strings, but not those enclosed in double quotes already, so I can swap them with a script. Make sense?

Thus, in the following examples, sentences #1, 2, 4, 6 and 8 are OK, while sentences #3, 5, and 7 contain incorrectly nested single quotes, which I’d like to swap:

  1. This is a sentence.
  2. This is a sentence “with double quotes.”
  3. This is a sentence ‘with single quotes.’
  4. This is a sentence “with a ‘nested single quote.’ Sometimes there are ‘more than one.'”
  5. This is a sentence ‘with a “nested double quote.” Sometimes there are “more than one.”‘
  6. This is a sentence “without a double ‘closing quote,’ which is common in this text.
  7. This is a sentence ‘without a single “closing quote,” common too, unfortunately.
  8. I don’t want to match apostrophes, however. That won’t work.

(bold face indicates the matches I’d like to make with the RegEx, so I can swap quotes.)

The point: I am trying to quote extended passages which already have quotes within them. This requires me to swap their doubles with singles.

Is this possible? I’ve been trying for hours, and I can’t seem to get it. Any help appreciated.

  • 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-06-16T21:39:15+00:00Added an answer on June 16, 2026 at 9:39 pm

    I don’t think regular expressions are the way to go for this one. Why not just scan through the text yourself?

    (pseudocode)

    for each char in text
    
        if char is `"`, then ignore until next `"`
        else if char is `'` (and not part of a contraction), then capture until next `'` or `.`
    
    end for
    

    I foresee future issues with this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.