title: passing variable to a regexp in javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex">Escape string for use in Javascript regex</a>  </p>
  </blockquote>
  
  
  
  <p>I have a msg like this:</p>
  
  <blockquote>
    <p><strong>Max {0} chars allowed in {1}</strong></p>
  </blockquote>
  
  <p>And I have a function to create a message using the arguments passed as</p>
  
  <pre><code>for(var i = 0; i &lt; agrs.length; i++){
      reg = new RegExp('\{'+i+'\}', 'gi');
      key = key.replace(reg,agrs[i])
  }
  </code></pre>
  
  <p>The problem is that it's not able to take the param <code>i</code> to create the reg exp.</p>
  
  <p>What's the way to achieve this?</p>