RegExp.lastIndex (Property)

A character index within the searched string immediately following the previous match.


ECMAScript edition - 3
JavaScript - 1.2
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Netscape Enterprise Server - 3.0
Opera - 5.0
Property/method value type:Number primitive
JavaScript syntax:-myRegExp.lastIndex

The lastIndex property is set to point at the character following the previous match. This allows you to build an iterator that cycles according to the matches for the search pattern within the source string.

When a null result is returned from the RegExp.exec() method, this value is set to 0.

The RegExp.exec() method uses the lastIndex property as its starting point for the next search. This means that if you prematurely exit the pattern searching iterator, you should also manually set this value to 0 as well. This will allow the same RegExp object to be used with another pattern (or the same one) to search a different string.


See also:RegExp.exec(), String.match(), String.replace(),


ECMA 262 edition 3 - section -