Today, while working with regular expressions in JavaScript (Firefox 3 on Windows Vista), I encountered a peculiar behavior.
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
Despite the regular expression appearing to be correct, there seems to be an issue with the output in the console.log
calls.
Surprisingly, Internet Explorer 7 and Chrome both show expected behavior: format[1]
returns "%A" (surprisingly, Internet Explorer 7 isn't as buggy as anticipated...)
Could this discrepancy in output be a bug in Firefox, or perhaps a little-known "feature"?