Updating a string with string.replace in JS : <p>I have the following question:
I have an array ['cd', 'ef', 'kl'] and a string 'ab(AA)ef(LL)ij(EX)'. I'd like to replace the text between parentheses (AA)s with 'cd', 'ef' and 'ij' respectively to make it 'ab(cd)ef(gh)ij(kl)'. I've written a code to find text between brackets</p>

<pre><code>var s = 'ab(cd)ef(gh)ij(kl)';
var regExp = /\((.+?)\)/g;
var found = [], r;
while(r = regExp.exec(s)) {
    found.push(r[1]);
}
</code></pre>

<p>but what should I do next? String.replace(re, found[x]) replaces all brackets with just the first one, as it should, and if I remove /g flag, it finds only the first occurrence (again, as it should). A bit stuck here, could you give me a hint please?</p>
