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 7711641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:25:37+00:00 2026-06-01T01:25:37+00:00

I thought to share this relatively smart problem with everyone here. I am trying

  • 0

I thought to share this relatively smart problem with everyone here.
I am trying to remove unbalanced/unpaired double-quotes from a string.

My work is in progress, I might be close to a solution. But, I didn’t get a working solution yet. I am not able to delete the unpaired/unpartnered double-quotes from the string.

Example Input

string1=injunct! alter ego."
string2=successor "alter ego" single employer"  "proceeding "citation assets"

Output Should be

string1=injunct! alter ego.
string2=successor "alter ego" single employer  proceeding "citation assets"

This problem sound similar to
Using Java remove unbalanced/unpartnered parenthesis

Here is my code so far(it doesn’t delete all the unpaird double-quotes)

private String removeUnattachedDoubleQuotes(String stringWithDoubleQuotes) {
    String firstPass = "";

    String openingQuotePattern = "\\\"[a-z0-9\\p{Punct}]";
    String closingQuotePattern = "[a-z0-9\\p{Punct}]\\\"";

    int doubleQuoteLevel = 0;
    for (int i = 0; i < stringWithDoubleQuotes.length() - 3; i++) {
        String c = stringWithDoubleQuotes.substring(i, i + 2);
        if (c.matches(openingQuotePattern)) {
            doubleQuoteLevel++;
            firstPass += c;
        }
        else if (c.matches(closingQuotePattern)) {
            if (doubleQuoteLevel > 0) {
                doubleQuoteLevel--;
                firstPass += c;
            }
        }
        else {
            firstPass += c;
        }
    }

    String secondPass = "";
    doubleQuoteLevel = 0;
    for (int i = firstPass.length() - 1; i >= 0; i--) {
        String c = stringWithDoubleQuotes.substring(i, i + 2);
        if (c.matches(closingQuotePattern)) {
            doubleQuoteLevel++;
            secondPass = c + secondPass;
        }
        else if (c.matches(openingQuotePattern)) {
            if (doubleQuoteLevel > 0) {
                doubleQuoteLevel--;
                secondPass = c + secondPass;
            }
        }
        else {
            secondPass = c + secondPass;
        }
    }

    String result = secondPass;

    return result;
}
  • 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-01T01:25:39+00:00Added an answer on June 1, 2026 at 1:25 am

    You could use something like (Perl notation):

    s/("(?=\S)[^"]*(?<=\S)")|"/$1/g;
    

    Which in Java would be:

    str.replaceAll("(\"(?=\\S)[^\"]*(?<=\\S)\")|\"", "$1");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just ran into this recently and I thought it'd be helpful to share. The
Took me a while to find an answer for this so thought I'd share
Just thought I'd share this in case anyone else has run into this. I
I recently came across an IE7 only bug that I thought I'd share so
I thought I heard that py2exe was able to do this, but I never
I thought I had seen a bug report about this on the jQuery site,
I thought I'd offer this softball to whomever would like to hit it out
I'm new to ASP.NET MVC and jQuery, so I thought I'd share how I
I need a relatively efficient way to share data between Matlab and R .
I'm trying to share an NSArray object between several different view controllers and my

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.