title: Javascript regular expression - string to RegEx object
body: <p>I am sure its something pretty small that I am missing but I haven't been able to figure it out.</p>
  
  <p>I have a JavaScript variable with the regex pattern in it but I cant seem to be able to make it work with the RegEx class</p>
  
  <p>the following always evaluates to false:</p>
  
  <pre><code>var value = "someone@something.com";
  var pattern = "^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$"
  var re = new RegExp(pattern);
  re.test(value);
  </code></pre>
  
  <p>but if I change it into a proper regex expression (by removing the quotes and adding the <code>/</code> at the start and end of the pattern), it starts working:</p>
  
  <pre><code>var value = "someone@something.com";
  var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/
  var re = new RegExp(pattern);
  re.test(value);
  </code></pre>
  
  <p>since I always get the pattern as a string in a variable, I haven't been able to figure out what I am missing here.</p>