Definition and Usage The lastIndex property specifies the index (placement) in the string where to start the next match. The index is a nu...
Definition and Usage
The lastIndex property specifies the index (placement) in the string where to start the next match.The index is a number specifying the placement of the first character after the last match.
This property only works if the "g" modifier is set.
Syntax
RegExpObject.lastIndex |
Example
In the following example we will see the index of the string after a match is found:<script type="text/javascript"> var str = "The rain in Spain stays mainly in the plain"; var patt1 = new RegExp("ain", "g"); patt1.test(str); document.write("Match found. index now at: " + patt1.lastIndex); </script> |