XRegExp breaks jQuery Animations

XRegExp is an open source JavaScript library that provides an augmented, extensible, cross-browser implementation of regular expressions, including support for additional syntax, flags, and methods.

It’s used by the popular SyntaxHighlighter script, which is in turn used by many websites (including this blog) to display syntax-highlighted source code on the client.  Thus, XRegExp has a rather wide usage base.

However, XRegExp conflicts with jQuery.  In IE, any page that includes XRegExp and runs a numeric jQuery animation will result in “TypeError: Object doesn't support this property or method”.

Demo (only fails in IE)

This bug is caused by an XRegExp fix for an IE bug in which the exec method doesn't consistently return undefined for nonparticipating capturing groups.  The fix, on line 271, assumes that the parameter passed to exec is a string.  This behavior violates the ECMAScript standard (section, which states that the parameter to exec should be converted to a string before proceeding.

jQuery relies on this behavior in its animate method, which parses a number using a regex to get the decimal portion.  (source)

Thus, calling animate with a number after loading XRegExp will fail in IE when XRegExp tries to call slice on a number.

Fortunately, it is very simple to fix XRegExp to convert its argument to a string first:

if (XRegExp) {
    var xExec = RegExp.prototype.exec;
    RegExp.prototype.exec = function(str) {
        if (!str.slice) 
            str = String(str);
        return xExec.call(this, str);
Here is an updated demo that uses this fix and works even in IE.


Thanks this really saved me ...

Is this fixed at http://xregexp.com/ now?

@LeoB: Given that the last released version was in 2010, one and a half years before I wrote this, I rather doubt it.


You may be right.

I just sent a mail to Steve.

Exactly the fix I needed. Thanks!

This has finally (!) been fixed in XRegExp 1.5.1. Thanks to both of you for reporting it.

I've been also been wondering how to figure this out.

May be tough for non-coders who are looking to implement this on their site.

These tips are very helpful.

The above article is nice and interesting, thank you willing to share! Greetings success of admin Percetakan Murah Rawamangun Jakarta Timur wish you deign to visit my website, thank you :)

This is one of the most informative post about Dissertation Help Service. I bookmarked this post and share with friends as well.

This is very nice blog i like this blog very much. here more than one important beautiful works will be displayed with quality essays

HP envy 5540 setup Envy 5540 Printer Basic setup and Driver download. Make easy steps to install Printer Driver from 123.hp.com/setup 5540

I love reading very much. Your article seemed instructive to me. Since I'm learning I'm interested in everything! And recently I was faced with the task of writing an ib extended essay. I sat long enough to realize that the task was too difficult for me. So I turned to the writing service, and I did great! Since I think the help is not plaintive, but instructive!

Yep, this... Really, this is the only thing I'm missing... really like it otherwise. cookie clicker slope unblocked

This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article.
Full stack Training in Indore

Post a Comment