Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<script>
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
for(i = 0; i < 4; i++) 
  {
  patt1.test(str);
  document.write(RegExp.lastMatch);  
  document.write(" found. index now at: " + patt1.lastIndex);
  document.write("<br>");
  }
</script>
</body>
</html>