August 1999
Intermediate to advanced
1488 pages
72h 53m
English
regexp.lastIndex
The lastIndex property of the RegExp object is used to get the index of where the next match begins.
Listing 6.219 shows how the lastIndex property is used. A regular expression for "is" is created and checked against the string. When found, results are written to the document.
<html> <body> <script language="JavaScript"> <!–– Hide </script> // creates a regular expression for "is". exp=/is*/g; str = "This is just a sample sentence."; myArray = exp.exec(str); document.write("Found: " + myArray[0] + ". Next match starts at index: " + exp.lastIndex); // End Hide ––> </script> </body> </html> ... |
Read now
Unlock full access