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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:10+00:00 2026-05-27T04:49:10+00:00

I have to escape two special characters and , in the string with the

  • 0

I have to escape two special characters ” and , in the string with the following rules.

Example:-

  • Mercu”ry should be converted into “Mercu””ry”
  • Mercu,ry should be converted into “Mercu,ry”
  • Mer”cu,ry should be converted into “Mer””cu,ry”

Rules:-

  • Meaning comma or double quote should be escaped with double quote.
  • Comma will escaped by wrapping the whole word in double quotes.
  • If Double quote is found, then it double quote should be added at its
    position. Also the whole word should be wrapped inside the double
    quotes.

Please suggest the regex pattern in javascript.

  • 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-27T04:49:10+00:00Added an answer on May 27, 2026 at 4:49 am
    var test = [
        'Mercu"ry', 'Mercu,ry', 'Mer"cu,ry', 'Mercury'
    ];
    
    
    for (x in test) {
        var s = test[x];
        if (s.indexOf('"') != -1) {
            s = s.replace(/"/g, '""');
        }
    
        if (s.match(/"|,/)) {
            s = '"' + s + '"';
        }
    
        alert(s);
    }
    

    Test: http://jsfiddle.net/ZGFV5/

    Try to run the code with Mer""cury 🙂

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

Sidebar

Related Questions

I have a bunch of string with special escape codes that I want to
I have an json output of the following (ignore the escape characters) {\sEcho\:1,\iTotalRecords\:10,\iTotalDisplayRecords\:10,\aaData\:[{\Job\:\developer\,\Name\:\kurt\},{\Job\:\plumber\,\Name\:\john\}]} which
I am trying to escape special characters in a TSQL query. I have done
Possible Duplicate: How can I removing escape characters using php? I have a string
Possible Duplicate: Escape string for use in Javascript regex I have a msg like
I have a method that looks like this: public static String escape(String text) {
I have a query that returns a string, as well as an escape character
I have a string that consists of some text \\computername.example.com\admin$. How would I do
I have two classes - Cd and Track which I'm trying to read into
I have a large (3GB), gzipped file containing two fields: NAME and STRING. I

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.