0

This seems like a simple problem but I can't seem to find the solution (or one that works) anywhere.

I have the following string:

"REDEACTED is a REDEACTED, REDEACTED, which focuses on the research and development of REDEACTED. It has 3 main brands, REDEACTED, a REDEACTED, and REDEACTED, a therapeutic line. It’s last brand is a REDEACTED line, which is set to be sold to REDEACTED offices. Through its subsidiaries, REDEACTED and REDEACTED, REDEACTED is able to cultivate, process and develop its REDEACTED through the 2 company’s facilities, which are located in REDEACTED. Though it hasn’t sold any of its product yet, it plans to solidify partnerships in the near future. "

and I'm trying to replace all instances of ’ with '.

I have tried things along the lines of

 newText = newText.replace("/'/gi", "'")
 newText = newText.replace("’", "'")
 newText = newText.replace("/’/gi", "'")

with no real luck, any suggestions?

4
  • 3
    Try this newText.replace(/'/gi, "'") remove the double quotes around Commented Apr 22, 2019 at 16:44
  • 1
    You want to pass a regex literal, not a regex in a string literal Commented Apr 22, 2019 at 16:45
  • 2
    .replace(/[‘’]/g,"'").replace(/[“”]/g,'"'); Commented Apr 22, 2019 at 16:57
  • Oh the issue was I wasn't removing the single quotes in the replace statement (this did the trick): newText = newText.replace(/’/g, "'") Commented Apr 22, 2019 at 17:14

2 Answers 2

1

I guess when using a real regex you need to remove the single quotes in the first parameter. Think this did the trick: newText = newText = newText.replace(/’/g, "'")

Sign up to request clarification or add additional context in comments.

Comments

0

Did you try like this way to simply remove that with '?

const regex = /’/ig;
const str = `REDEACTED is a REDEACTED, REDEACTED, which focuses on the research and development of REDEACTED. It has 3 main brands, REDEACTED, a REDEACTED, and REDEACTED, a therapeutic line. It’s last brand is a REDEACTED line, which is set to be sold to REDEACTED offices. Through its subsidiaries, REDEACTED and REDEACTED, REDEACTED is able to cultivate, process and develop its REDEACTED through the 2 company’s facilities, which are located in REDEACTED. Though it hasn’t sold any of its product yet, it plans to solidify partnerships in the near future.`;
const subst = `'`;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log("Substitution result:\n", result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.