I am attempting to find a sentence in a paragraph (contained in a textarea), and highlight it. All works well if the sentence does NOT contain opening and closing parenthesis, such as the example below. The replace method is unable to replace the string with its equivalent surrounded by the "mark" tags. Can anyone advise how I can update my Regex to find and replace a string containing parentheses? Do I need to find and replace all parentheses with "/(" and "/)" first?
const text = "An economy is composed of suppliers (workers) and demanders (firms)."
const regex = new RegExp(text, "\d");
// regex returns: /The market for labor, then, is composed of suppliers (workers) and demanders (firms). /
console.log("REGEX:", regex);
let match = text.replace(regex, "<mark>$&</mark>");
console.log("MATCH:", match);