title: Using RegExp to dynamically create a Regular Expression, and filter content
body: <p>I am struggling with using the <code>RegExp</code> object to allow me to dynamically create an expression, and apply it to a group of elements.</p>
  
  <p><a href="http://jsfiddle.net/2R8Wq/4/" rel="noreferrer">Here is a jsFiddle</a>, below is the code:</p>
  
  <pre><code>&lt;div id='selectors'&gt;&lt;span&gt;A-F&lt;/span&gt;&lt;span&gt;G-L&lt;/span&gt;&lt;span&gt;M-S&lt;/span&gt;&lt;span&gt;T-Z&lt;/span&gt;&lt;/div&gt;
  
  &lt;a hreh=#&gt;Astring&lt;/a&gt;
  &lt;a hreh=#&gt;Cstring&lt;/a&gt;
  &lt;a hreh=#&gt;Xstring&lt;/a&gt;
  &lt;a hreh=#&gt;Dstring&lt;/a&gt;
  &lt;a hreh=#&gt;Zstring&lt;/a&gt;
  
  $('div#selectors span').click(function(){
          expression = "/^["+$(this).html()+"].*$/";
  
          rx = RegExp(expression,'i');
          console.log(rx,'expression');
          $("a").each(function(){
  
                      if($(this).html().match(rx) !== null){
                          $(this).addClass('selected');
                      }
          });
  
      })
  </code></pre>