title: Store regex in string in javascript?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/874709/converting-user-input-string-to-regular-expression">Converting user input string to regular expression</a><br>
    <a href="https://stackoverflow.com/questions/5172183/javascript-new-regexp-from-string">javascript new regexp from string</a>  </p>
  </blockquote>
  
  
  
  <p>I am having a little bit of a problem with regex in javascript (I'm not too used to regex in javascript just yet). I wanna replace some stuff in a string and I noticed the syntax for writing regex seems to be without <code>'</code> or <code>"</code> like this: <code>var replacedtitle = title.replace(/\[.*?\]/g, "");</code></p>
  
  <p>Now this all work as intended, but I want the user to be able to add his own regexes from the interface without changing the code (I'm doing a private project for a friend who doesn't code, and I want to be able to just send him the regexes to input when something new needs to be replaced instead of me repackaging everything every time). I did this by having a xul textbox (this is a firefox addon, but should be the same as if it was a html textbox) where he inputs the regexes, it gets added to a json object and saved. I tried doing something like this:</p>
  
  <pre><code>var replacedtitle = "";
  for(a = 0; a &lt; regex.data.length;a++){
      replacedtitle = title.replace(regex.data[a].regex, "");
  }
  </code></pre>
  
  <p>but it wont work. I suspect it's because <code>regex.data[a].regex</code> would be taken as a string, yet replace() doesn't seem to take string as the first parameter, right?</p>
  
  <p>I am a bit uncertain about this, any help would be much appreciated.</p>