JavaScript lastIndex Property
JavaScript RegExp Object
Definition and Usage
The lastIndex property specifies the index at which to start the next match.
Note: This property only works if the "g" modifier is set.
This property returns an integer that specifies the character position
immediately after the last match found by exec( ) or test( ) methods.
Note: exec( ) and test( ) reset lastIndex to 0 if they do not get a
match.
Syntax
Example
Example
Do a global search for "ain" in a string, and output the index after a match is found:
<script type="text/javascript">
var str="The rain in Spain stays mainly in the plain";
var patt1=/ain/g;
while (patt1.test(str)==true)
{
document.write("'ain' found. Index now at: "+patt1.lastIndex);
document.write("<br />");
}
</script> |
Try it yourself »
|
JavaScript RegExp Object

Whether you're new to XML or already an advanced user,
the user-friendly views and powerful entry helpers,
wizards, and debuggers in XMLSpy are designed to meet your XML
and Web development needs from start to finish.
New features in Version 2010!
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- XBRL validator, taxonomy editor, taxonomy wizard
- Support for Office Open XML (OOXML)
- Graphical WSDL 1.1/2.0 editor & SOAP debugger
- JSON editing & conversion
- Java, C#, C++ code generation
- And much more!
Download a free trial today!
|
|
|
|