Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <script> 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> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_regexp_lastindex by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:27:40 GMT --> </html>
Result:
Try it Yourself - © w3schools.com