Why doesn't the javascript replace global flag work in Chrome or IE, and how to I work around it?
<p>According to <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace#Example.3a_Using_global_and_ignore_with_replace" rel="nofollow">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace#Example.3a_Using_global_and_ignore_with_replace</a> I should be able to easily replace multiple patterns just by using str.replace('what to replace', 'replace with', 'flags') and setting the flags to 'g'. </p>

<p>It works perfect in Firefox 3.6. But in Chrome and IE8, it only replaces the first 'what to replace'. </p>

<p>I can use the str.replace(/what to replace/gi, 'replace with') syntax. But I'm pulling the 'what to replace' out of an array, which makes it hard to add the flags in that syntax.</p>

<p>Here's the code I'm trying to use. How to I modify it to work in Chrome as well as Firefox?</p>

<pre><code>function generateQuestion()
{
    //alert('variable length: '+variableList.length);
    for(i=0;i&lt;variableList.length;i++)
    {
        variable = variableList[i];
        rep = replacementList[i];
        flags = "gi";
        //alert('Variable: '+variable+' rep: '+rep+' flags: '+flags+'/n'+questionText);
        questionText = questionText.replace(variable, rep, flags);
    }
}
</code></pre>

<p>And why do I have to bother modifying it at all? Shouldn't Chrome evaluate the javascript as described in the link?</p>
