/.?e.?/ matches entire string, rather than expected substring
firefox, javascript, regex
Solution
As tiffon said, this is a bug in SpiderMonkey (Firefox's JavaScript engine).
In SpiderMonkey, we use the RegExp engine from Safari's JavaScriptCore JS engine, and inherited the bug from that. I filed bug 119191 for the bug in JSC.
Problem
In Internet Explorer 10, this: ``` 'abcdefghi'.match(/.?e.?/) ``` evaluates to `['def']`, as I'd expect, but in Firefox 21.0, it evaluates to `['abcdefghi']`. (See this jsFiddle.) I get the same sort of unexpected behavior for certain other regexes that both begin and end with optional content, such as `/.?e.{0,2}/` and `/.{0,2}e.{0,2}/`; however, commenters point out various similar regexes, such as `/\S?e\S?/` and `/(?:.?e.?)/`, that are not affected. The same applies to the `replace` method. Am I missing something obvious? Is there some deep reason for this behavior?