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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:53:22+00:00 2026-06-13T15:53:22+00:00

I was trying to replace this (‘ with (\’ and ‘) with \’) My

  • 0

I was trying to replace this (' with (\' and ') with \') My attempts were few as I’m not comfortable with RegExp.

What I tried was myText.replace(/\(\'/g, "(\')"); and myText.replace(/\'\)/g, "\')");

  • 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-13T15:53:23+00:00Added an answer on June 13, 2026 at 3:53 pm

    The problem is not your regex but your replacement. You need to escape the backslash, otherwise it (unnecessarily) escapes the ':

    myText = myText.replace(/\('/g, "(\\'");
    myText = myText.replace(/'\)/g, "\\')");
    

    With some slightly more advanced techniques (namely a capturing group and a lookahead) you can combine these into one regex:

    myText = myText.replace(/(\()'|'(?=\))/g, "$1\\'");
    

    The regex matches either (' or ' if it is followed by ) (without actually matching that). At the same time we “capture” the ( if it is there. The $1 in the replacement string puts the ( back in place if it was captured, and then simply writes out \'. There is no need to write the ) back. Because we used a lookahead, it was never part of the match.

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

Sidebar

Related Questions

I am trying to do this regex match and replace but not able to
I am trying to replace this in the below example with $$Ashok.I am not
I'm trying to replace something like this: NSSomeFunction(@some var, @another one) With: NSSomeOhterFunction(@some var)
Hi guys thanks for pay attention to this. Well im trying to replace every
I am trying to use this regex (JS): /\/\*(.*)\*\//g To replace /* sdandsads */
I'm trying to take this string where lowercase(pdd.last_name) like 'albert%' and replace pdd with
I am trying to learn javascript i have this code: x=x.replace(/^\s+|\s+$/g,); can i have
I am trying to replace this iwdnowfreedom[body_style][var] with this iwdnowfreedom_body_style_var in the name attributes
I'm trying to replace this XML: <name type=personal authority=local> <namePart>Gertrude</namePart> <namePart type=termsOfAddress>Aunt</namePart> <role> <roleTerm
I'm starting out with PDO and trying to replace this code, which works: $dbh->query(INSERT

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.