I am trying to remove the text from the last paranthesis within a string using jQuery, I am able to remove the paranthesis from the string but the code removes every paranthesis and I need the last one to be removed only. For example I have the following string “This is a (test) string (where) last paranthesis (needs) to be (removed) ” I wrote the code below to remove the paranthesis and text within the parenthesis.
$('p').text(function(_, text) {
return text.replace(/(.*?)/g, '');
});
The code I tried removed all the paranthesis from within the string, I need to remove the last paranthesis from within the string.