24.157. RegExp.lastIndex: the starting position of the next matchECMAScript v324.157.1. Synopsisregexp.lastIndex 24.157.2. DescriptionlastIndex is a read/write property of RegExp objects. For regular expressions with the "g" attribute set, it contains an integer that specifies the character position immediately following the last match found by the RegExp.exec( ) and RegExp.test( ) methods. These methods use this property as the starting point for the next search they conduct. This allows you to call those methods repeatedly, to loop through all matches in a string. Note that lastIndex is not used by RegExp objects that do not have the "g" attribute set and do not represent global patterns. This property is read/write, so you can set it at any time to specify where in the target string the next search should begin. exec( ) and test( ) automatically reset lastIndex to 0 when they fail to find a match (or another match). If you begin to search a new string after a successful match of some other string, you have to explicitly set this property to 0. 24.157.3. See AlsoRegExp.exec( ), RegExp.test( ) |