title: jQuery Regex from String
body: <p>I have the following Regex that comes from a data Attribute on an HTML Element:</p>
  
  <pre><code>/^$|^[0-9]{2}.[0-9]{4}$/g
  </code></pre>
  
  <p>When I (manually) do:</p>
  
  <pre><code>/^$|^[0-9]{2}.[0-9]{4}$/g.test('01.2012');
  </code></pre>
  
  <p>It works and returns <code>true</code>.</p>
  
  <p>When I put the Regex in a Variable like so:</p>
  
  <pre><code>var inputRegex = $(this).attr('data-validation');
  </code></pre>
  
  <p>And do:</p>
  
  <pre><code>inputRegex.test(input);
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>inputRegex.test is not a function.</p>
  </blockquote>
  
  <p>I know that this is because inputRegex is a String and String does not have a test function, but when I create a RegExp object (<code>new RegExp($(this).attr('data-validation')</code>) it breaks my Regular Expression by escaping:</p>
  
  <pre><code>/\/^$|^[0-9]{2}.[0-9]{4}$\/g/
  </code></pre>
  
  <p>How can I use the data-attribute value as a Regular Expression? Please note that I cannot do: <code>var regex = new RegExp(string, 'g');</code> because the Regular Expression(s) come predefined from the attribute. </p>