Subj : Re: lastIndex property of newly created RegExp object To : Martin.Honnen From : Brendan Eich Date : Mon Nov 29 2004 11:33 am Martin Honnen wrote: > Now section 15.10.4.1 of ECMA says that for a newly created RegExp object > "The lastIndex property of the newly constructed object is set to 0." See 7.8.5 Regular Expression Literals: A regular expression literal is an input element that is converted to a RegExp object (section 15.10) when it is scanned. The object is created before evaluation of the containing program or function begins. Evaluation of the literal produces a reference to that object; it does not create a new object. Two regular expression literals in a program evaluate to regular expression objects that never compare as === to each other even if the two literals' contents are identical. A RegExp object may also be created at runtime by new RegExp (section 15.10.4) or calling the RegExp constructor as a function (section 15.10.3). So the SpiderMonkey and Rhino engines create one RegExp object for each source Regular Expression Literal, before evaluation of the containing program or function begins (i.e., "when [the literal] is scanned"). > with MSIE 6 it always shows 0 for the lastIndex. Another MS JScript bug. > Any thoughts on why Spidermonkey and Rhino somewhere store and restore > the lastIndex property between function calls? They follow the spec. There is no new regexp per call, only one per literal scanned. /be .