I came across a strange behaviour when doing some regexes in Javascript today (Firefox 3 on Vista).
var str = "format_%A";
var format = /(?:^|\s)format_(.*?)(?:\s|$)/.exec(str);
console.log(format); // ["format_%A", "%A"]
console.log(format[0]); // "format_undefined"
console.log(format[1]); // undefined
There's nothing wrong with the regex, as you can see it has matched the correct part in the first console.log
call.
Internet Explorer 7 and Chrome both behave as expected: format[1]
returns "%A" (well, IE7 doing something right was a bit unexpected...)
Is this a bug in Firefox, or some "feature" I don't know about?