• 회원가입
  • 로그인
  • 구글아이디로 로그인

[RegExp] JS - lastIndex 속성 - 일치 직후의 문자 위치 반환 (= lastIndex속성 = 라스트인덱스 속성)

목차
  1. lastIndex 예제 - 일치 여부 체크할 다음 시작점
  2. lastIndex 정의
  3. lastIndex 구문

 

lastIndex 예제 - 일치 여부 체크할 다음 시작점

 

<p id="demo"></p>


<script>

let text = "Welcome to Homzzang.com !!";

let pattern = /om/g;


let result = "";

while (pattern.test(text)==true)  {

  result += "다음 일치 시작점: " + pattern.lastIndex + "<br>";

}


document.getElementById("demo").innerHTML = result;

</script>

 

결과보기


PS. 결과값

다음 일치 시작점: 6

다음 일치 시작점: 14

다음 일치 시작점: 23

 

 

lastIndex 정의

 

일치 여부 체크할 다음 시작 인덱스(=색인번호) 정수 반환.

 


 

1.

  • g 수정자 설정된 경우에만 작동.
  • exec() / test() 메서드에서 찾은 마지막 일치 직후의 문자 위치를 지정하는 정수를 반환.
  • exec() / test() 메서드는 일치 않을 시 lastIndex를 0으로 재설정.

 

2.

  • ECMAScript1(ES1 : JavaScript 1997)
  • 모든 브라우저 지원.

 

 

lastIndex 구문

 

RegExpObject.lastIndex

 


[반환값]

 

exec() / test() 메서드에서 찾은 마지막 일치 직후의 문자 위치를 지정하는 정수 반환.

 



분류 제목
DOM_Attribute JS - attr.isId -
DOM_Attribute JS - attr.name -
DOM_Attribute JS - attr.value -
DOM_Attribute JS - attr.specified -
DOM_Attribute JS - nodemap.getNamedItem() 메서드 -
DOM_Attribute JS - nodemap.item() 메서드 -
DOM_Attribute JS - nodemap.length -
DOM_Attribute JS - nodemap.removeNamedItem() 메서드 -
DOM_Attribute JS - nodemap.setNamedItem() 메서드 -
Window_Console JS - console.assert() 메서드 - 표현식이 FALSE인지 확인 (= 표현식 거짓 여부 체크 …
Window_Console JS - console.clear() 메서드 - 콘솔 지우기 (=콘솔창 청소 = console.clear메…
Window_Console JS - console.count() 메서드 - 콘솔창에서 카운트하기 (= 숫자 세기 = console.co…
Window_Console JS - console.error() 메서드 - 콘솔창에서 에러메시지 띄우기 (= console.error메…
Window_Console JS - console.group() 메서드 - 콘솔에서 메시지 그룹 생성 시작 (= console.grou…
Window_Console JS - console.groupCollapsed() 메서드 - 콘솔에서 접힌/축소된 메시지 그룹 시작 지정…
Window_Console JS - console.groupEnd() - 메시지 그룹의 끝/종료 지점 지정 (= console.grou…
Window_Console JS - console.info() 메서드 - 콘솔에 메시지 쓰기 (= console.info메서드 = 콘솔…
Window_Console JS - console.log() 메서드 - 콘솔에 메시지 쓰기 (= console.log메서드 = 콘솔로그…
Window_Console JS - console.table() 메서드 - 콘솔에 테이블 쓰기 (= console.table메서드 = …
Window_Console JS - console.time() 메서드 - 콘솔창에서 타이머 시작 (= console.time메서드 = …
23/67
목록
찾아주셔서 감사합니다. Since 2012