title: Make Javascript regular expression case insensitive
body: <p>I'm using a jquery function I found to find words in a div and highlight them.  I'm using this along with a search tool so the case is not always going to match the words exactly.  How can I convert this to make it case insensitive? </p>
  
  <pre><code>$.fn.highlight = function(what,spanClass) {
      return this.each(function(){
          var container = this,
              content = container.innerHTML,
              pattern = new RegExp('(&gt;[^&lt;.]*)(' + what + ')([^&lt;.]*)','g'),
              replaceWith = '$1&lt;span ' + ( spanClass ? 'class="' + spanClass + '"' : '' ) + '"&gt;$2&lt;/span&gt;$3',
              highlighted = content.replace(pattern,replaceWith);
          container.innerHTML = highlighted;
      });
  }
  </code></pre>