The lastIndex property of RexExp
The RegExp object has what is called the lastIndex property. This property gives you the index where the next search will start in the available string. This property can only be used when the global flag is set for the RegExp object. You can use either the test() or exec() methods. The following code illustrates this:
var availableString = "We have a dog in our compound.";
var re = /dog/g;
The first statement in the script declares the variable for the available string. The next statement declares the RegExp object, re. Note the global flag. The statement after that executes the exec() method of the re (RexExp) object. The exec() or test() method is always executed with a RegExp object.
The equivalent for this lastIndex property does not exist for any string method. However, with the string method search(), you can get an index which you can call the firstIndex.