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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:48:27+00:00 2026-06-04T17:48:27+00:00

Having some trouble with backslashes regular expressions. I want to remove all dual backslashes

  • 0

Having some trouble with backslashes regular expressions. I want to remove all dual backslashes (or any multiple of 2) that exist on any string property of an object. I do not want to remove single backslashes nor the last backslash in an odd number of backslashes (e.g., leave one backslash remaining in a set of five continuous backslashes \\\\\ -> \).

The code is here:

http://jsfiddle.net/59Zau/

//removes all dual backslahes on all string properties on an object
var removeDualBackslash = function (obj) {
    var ret = null;
    if (typeof(obj) == "string") {
        obj = obj.replace(/\\\\/g,"");
        return obj;
    } else if (typeof(obj) == "number") {
        return obj;
    } else if (typeof(obj) == "array") {
        ret = [];
    } else {
        ret = {};
    }
    for (var key in obj)
        ret[key] = removeDualBackslash(obj[key]);
    return ret;
};

var oJSON = {"t4m_data_in":{"no_data":"No data \\passed in."}};

oJSON = removeDualBackslash(oJSON);

console.log(oJSON.t4m_data_in.no_data);​

As you can see from the console.log, one of the backslashes remains. Does anyone know what regular expression I need to remove both of them?

  • 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-04T17:48:28+00:00Added an answer on June 4, 2026 at 5:48 pm

    The problem is in your JSON string. The "\\" there is already a single backslash.

    >> console.log("No data \\passed in");
    No data \passed in
    

    Are you sure you don’t want to just remove all backslashes instead?

    obj = obj.replace(/\\/g,"");
    

    Doing so would remove literal backslashes like "\\" but would still preserve other escape sequences like "\n" because in those cases the backslash is just in the string literal, not in the actual string.

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

Sidebar

Related Questions

So having some trouble with a class methods. I'll post all the information that
I´m having some trouble retrieving a collection of strings in a projection: say that
Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
Im having some trouble with an Array in C++. See I want to let
having some trouble with my razor syntax gives a Parsor error saying that The
having some trouble with a Thread (CanvasThread) that is intermittently pausing at random points
Having some trouble getting this to work... I basically want the report to look
Having some trouble understanding variable scope within a class structure. I want to create
Im having some trouble reading xml files using jquery that containts swedish chars (åäö)
I'm having some trouble searching for any similar match in two fields. For example

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.