Layout Options

  • Fixed Header
    Makes the header top fixed, always visible!
  • Fixed Sidebar
    Makes the sidebar left fixed, always visible!
Regular Expression Last index

Description

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.

This property has the form:

RegExpObject.lastIndex

Note: exec( ) and test( ) reset lastIndex to 0 if they do not get a match.

Examples

The following example shows the basic use of this property.

<script>
var str="The rain in Spain stays mainly in the plain";
var pat=/ain/g;
while (pat.test(str)==true)
{
  document.write("'ain' found. Index now: " + pat.lastIndex);
  document.write("<br />");
}
</script>

This produces the following result:

Browser Support

Firefox IE Chrome Opera Safari