Saurabh Aren Saurabh Aren - 1 year ago 49
HTML Question

Replace code for single quote is not working

Replace code is not working for single quote so please help me.
Some place it is working and some place it will not work.

Javascript Code:

var demo = "Broadcasted on Zee TV from Monday to Friday, the Indian television soap opera Kumkum Bhagya has long been revolving around the mystery of Tanu’s pregnancy. Tanu, a cunning, sly and guileful character in the Kumkum Bhagya serial has been fooling Abhi, the rock star. She is actually pregnant with Nikhil, her ex-boyfriend, but claims to be the mother of Abhi’s child. Except Abhi, almost everyone in the show knows who Tanu is pregnant with. But, the mystery will remain unrevealed until Abhi knows the reality of Tanu’s pregnancy. The coming episodes of Kumkum Bhagya, Pragya's DNA disclosure is likely to reveal the secret.";
var demo1 = demo.replace(/[']/g,";");
document.getElementById("hello").innerHTML = demo1;

HTML Code:

<div id="hello">

Please use this as reference:

Answer Source

In your string you have the unicode character 'right single quotation mark' and also an apostrophe, but in your regular expression you have an apostrophe which is a different character. If you want to replace both characters you need to include both in your regular expression:

var demo1 = demo.replace(/['’]/g,";");

Specifically compare: Tanu’s (right single quotation mark) and Pragya's (apostrophe)

To make this easy to type you can use the unicode escape sequence instead of the character:

var demo1 = demo.replace(/['\u2019]/g,";");