Returns the character position where the next match begins in a searched string.
SyntaxRegExp.lastIndex
Examples
The following example illustrates the use of the lastIndex property. This function iterates a search string and prints out the index and lastIndex values for each word in the string.
function RegExpTest()
{
var ver = Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion())
if (ver < 5.5)
{
document.write("You need a newer version of JavaScript for this to work");
return;
}
var src = "The quick brown fox jumps over the lazy dog.";
var re = /\w+/g;
var arr;
while ((arr = re.exec(src)) != null)
{
document.write ("<br />");
document.write (arr.index + "-" + re.lastIndex + " ");
document.write (arr);
}
}
Remarks
The object associated with this property is always the global RegExp object.
The lastIndex property is zero-based, that is, the index of the first character is zero. Its initial value is -1. Its value is modified whenever a successful match is made.
The lastIndex property is modified by the exec and test methods of the RegExp object, and the match , replace , and split methods of the String object.
The following rules apply to values of lastIndex :
Microsoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4