Solution 1 :

Just escape the brackets to fix this: text.replace(/)/g, "right")

function myFunction() {
  var text = document.getElementById("ansiText").value; 
  var finalText = text.replace(/)/g, "right");
 
  document.getElementById("ansiText").value = finalText;
}

Problem :

function myFunction() {
  var text = document.getElementById("ansiText").value; 
  var finalText = text.replace(/)/g, "right");
 
  document.getElementById("ansiText").value = finalText;
}

I want to find and replace ( as left and ) as right.
But its didn’t work if i write ) in code, its create errors. How can I write ( in replace function?

Comments

Comment posted by Jan Stránský

“its create errors” please always provide relevant errors

Comment posted by Jan Stránský

just escape the brackets:

By