High cpu consumption due to a jquery regex patch
<p>I am going to work on a project developped by someone else. I don't have any contact with this guy.
I noticed a very high cpu consumption by the browser when the page is loaded.</p>

<p>After some investigations, i think that the problem comes from a patch of jquery regex but I don't clearly understand the goal of this patch and the cause of this cpu consumption.</p>

<pre><code>jQuery.expr[':'].regex = function(elem, index, match) {
   var matchParams = match[3].split(',');
   var validLabels = /^(data|css):/;
   var attr = {
      method:
         matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr',
         property: matchParams.shift().replace(validLabels,'')
   };
   var regexFlags = 'ig';
   var regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
   return regex.test(jQuery(elem)[attr.method](attr.property));
};
</code></pre>

<p>I have seen that this method was constanly called.</p>

<p>I have several calls to regex like this one.</p>

<pre><code>$(':regex(id,DelCompo.*$)').livequery('click',function(e) {
   //...
}
</code></pre>

<p>If I comment them, the cpu consumption seems to be normal. Of course, some features are broken.</p>

<p>I think the problem comes from this new regex function. Is it correct?
What would be the best way to fix this problem?</p>

<p>Thanks</p>
