English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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‹/›
All browsers fully support the lastIndex property:
Property | |||||
lastIndex | Yes | Yes | Yes | Yes | Yes |
Return Value: | Returns an integer specifying the position of the character after the last match |
---|---|
JavaScript Version: | ECMAScript 1 |