contents   index   previous   next

RegExp lastIndex




The character position after the last pattern match and which is the basis for subsequent matches when finding multiple matches in a string. That is, in the next search, lastIndex is the starting position. This property is used only in global mode after being set by using the "g" attribute when defining or compiling a search pattern. RegExp exec() and RegExp test() use and set the lastIndex property. If a match is not found by one of them, then lastIndex is set to 0. Since the property is read/write, you may set the property at any time to any position.


Read/write property.



RegExp exec(), String match()



var str = "one tao three tio one";

var pat = /t.o/g;


   // pat.lastIndex == 7 


RegExp multiline