Site icon ben lowery

Finding those damn trailing commas

Internet Explorer has this wonderful behavior where it completely refuses to load a JavaScript file when it encounters a trailing comma. That is, something that looks like this:

var f = { foo: "bar", baz: { go: "yes" }, };

I got sick of trying to find these beasties and came up with this regex instead:

}[\s\n]*,[\s\n]*[^\[{\w\n\s/\*\"]

Works like a charm in TextMate. Might work in grep too? Anyway, it’s a good way to find your headache quickly. :)

Exit mobile version