English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript RegExp lastIndex Property

 JavaScript RegExp RegExp Object

lastIndexThis property defines the index to start the next match.

This property returns an integer that specifies the character position after the last match found by the exec() or test() method.

Both the exec() and test() methods will automatically reset lastIndex to 0 when no match is found.

Note:Only when the following setting is enabled: g This property takes effect only when the identifier (modifier) is specified.

Syntax:

regex.lastIndex
var str =39;The question is To be, or not to be, that is to be.';
var regex = /to be/gi;
while (regex.test(str) == true) {
   document.write("'to be' found. Start the next match at index: " + regex.lastIndex);
   document.write("<br>");
}
Test and See‹/›

Browser Compatibility

All browsers fully support the lastIndex property:

Property
lastIndexYesYesYesYesYes

Technical Details

Return Value:Returns an integer specifying the position of the character after the last match
JavaScript Version:ECMAScript 1

 JavaScript RegExp RegExp Object