exec()
exec() 메소드는 정규식 메소드입니다. 지정된 패턴에 대해 문자열을 검색하며 test()와 달리 regex 메서드는 찾은 텍스트를 객체로 반환합니다. 일치하는 항목이 없으면 null 이 표시됩니다. 출력으로. 자세히 논의합시다.
예시-1
다음 예에서는 exec()를 통해 변수 패턴 "est"를 확인합니다. 방법. exec() regex 메서드는 텍스트 전체에 걸쳐 주어진 패턴을 조사한 후 패턴을 객체로 반환했습니다. .
<html>
<body>
<script>
var obj = /est/.exec("Tutorix is the best e-learning platform");
document.write(
"The object is " + obj[0] + " and its position is " + obj.index);
</script>
</body>
</html> 출력
The object is est and its position is 16
예시-2
다음 예에서는 exec()를 통해 변수 패턴 "x"를 확인합니다. 방법. exec() regex 메소드는 텍스트 전체에 걸쳐 주어진 패턴을 면밀히 조사한 후 패턴을 객체로 반환했습니다.
<html>
<body>
<script>
var obj = /x/.exec("Tutorix is the best e-learning platform");
document.write(
"The object is " + obj[0] + " and its position is " + obj.index);
</script>
</body>
</html> 출력
The object is x and its position is 6