var text = "cat bat sat fat"; var pattern = /.at/g; var matches = pattern.exec(text); // 패턴 매칭 document.write(matches.input + "<br><br>"); //전달받은 문자열 document.write(matches.index + "<br>"); // 0에서 찾음 document.write(matches[0] + "<br>"); // cat document.write(pattern.lastIndex + "<br><br>"); // pattern객체의 lastIndex 3 matches = pattern.exec(text); // 패턴 매칭 document.write(matches.index + "<br>"); // 3부터 시작해서 4에서 찾음 document.write(matches[0] + "<br>"); // bat document.write(pattern.lastIndex + "<br><br>"); // lastIndex 7 matches = pattern.exec(text); // 패턴 매칭 document.write(matches.index + "<br>"); // 7부터 찾음 document.write(matches[0] + "<br>"); // sat document.write(pattern.lastIndex + "<br>"); // lastIndex 11