x
 
<html>
<body>
<script type="text/javascript">
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("ain found. index now at: " + patt1.lastIndex);
  document.write("<br />");
  }
</script>
</body>
</html>