lastIndex
RegExp
instance property
JS Home <<
JS Reference <<
RegExp <<
lastIndex
Description
Specifies the index to start the next match from.
lastIndex
only works when theg
flag has been set.
Syntax
Signature | Description |
---|---|
aRegExp.lastIndex | Returns a reference to the function that created the prototype. |
Parameters
None.
Examples
The code below displays the lastIndex
property of a RegExp
instances.
var aRegExp = /and/g;
var aString = new String 'one and two and three and four';
var flagValues = new Array();
var i = 0;
while (aRegExp.test(aString)==true) {
flagValues[i] = 'the word and found. Match will continue at index: '
+ aRegExp.lastIndex + '\n';
i++;
}
alert(flagValues);
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 9 - Regular Expressions