I have this kind of string, with a lot of parenthesis which might nest other parathesis, and so on:
[code]
var str=’Four score (and seven (years) ago) our fathers brought (forth onto) this continent’;
Now I want to use a regular expression to remove all the parenthesis along with the nested substrings. The text above should become:
[code]
var finalstr=’Four score our fathers brought this continent’;
First thing which came up into mind was a non-greedy RegExp to match everything between paranthesis:
[code]
/(.*?)/g
But that works only if there are no other inner parenthesis [I]nested inside the parenthesis
[code]
str=str.replace(/(.*?)/g,”);
returns
‘Four score [COLOR=”Red”]ago)
which is logical, as the replaced substrings are:
‘Four score [COLOR=”Red”]([COLOR=”Blue”] and seven (years[COLOR=”Red”])[COLOR=”Red”] ([COLOR=”Blue”]forth onto[COLOR=”Red”])
but this is not what I want.
I can not see how could I replace the “most inner”[COLOR=”Blue”] ()
Any ideas?