Flagrant Badassery

A JavaScript and regular expression centric blog

Safari Support with XRegExp 0.2.2

When I released XRegExp 0.2 several days ago, I hadn't yet tested in Safari or Swift. When I remembered to do this shortly afterwards, I found that both of those WebKit-based browsers didn't like it and often crashed when trying to use it! This was obviously a Very Bad Thing, but due to major time availability issues I wasn't able to get around to in-depth bug-shooting and testing until tonight.

It turns out that Safari's regex engine contains a bug which causes an error to be thrown when compiling a regex containing a character class ending with "[\\".

// These throw an error:
[ /[[\\]/ , /[^[\\]/ , /[abc[\\]/ ]

// ...While these are all fine:
[ /[\\[]/ , /[\[\\]/ , /[[]/ , /[\\]/ , /[[\\abc]/ , /[[\/]/ , /[[(\\]/ ]

// Testing:
try {
} catch (err) {
	/* Safari shows:
	"SyntaxError: Invalid regular expression: missing terminating ] for
	character class" */

As a result, I've changed two instances of [^[\\] to [^\\[] and upped the version number to 0.2.2. XRegExp has now been tested and works without any known issues in all of the following browsers:

  • Internet Explorer 5.5 – 7
  • Firefox
  • Opera 9.21
  • Safari 3.0.2 beta for Windows
  • Swift 0.2

You can get the newest version here.

There Are 4 Responses So Far. »

  1. Hi.

    I have now published my SweetXML parser, using your XRegExp.

    I developed it first without using your code, and you will be pleased to here that it was a 5 minute swap-in. Worked a dream, with no errors.


  2. Sweet!

    SweetButty seems like the perfect kind of project to use XRegExp… a regex intensive app, which becomes much more self-documenting though named capture.

  3. http://bugs.webkit.org/show_bug.cgi?id=14823

  4. Invite You to Review Our Fitness Coaching Service

    I am Caryn and the founder at THELOCATION3

    I’m reaching out to you because we are looking for fitness enthusiasts like you to test our online fitness coaching service.

    Go here: https://www.thelocation3.com/perfectbody to test the service.

    We have prepared a premium account for you, you can use it at no cost.

    Thank you for your time,

    Caryn Kover

    UNSUBSCRIBE : Reply “no email”

Post a Response

If you are about to post code, please escape your HTML entities (&, >, <).