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

[RegExp] JS - [0-9] 의미 - 대괄호안숫자포함 (= 대괄호안숫자 정규표현식)

[숫자] 예제 - 대괄호 안 숫자와 일치하는 숫자 출력

 

<button onclick="test()">결과보기</button>


<p id="hz"></p>


<script>

function test() {

    var str = "123456789";

    var patt = /[1-3]/g;

    var result = str.match(patt);

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

}

</script>



결과 보기

 

 

 

[숫자]  정의


대괄호안에 포함된 모든 개별 숫자 찾기

 



1.

대괄호 안 숫자는 임의의 숫자 또는 숫자 범위 일 수 있음.


[01234 ..] - 대괄호 안의 모든 개별 숫자

[0-9] - 0에서 9까지의 모든 개별 숫자


2.
모든 주요 브라우저 지원

 


 

cf.



[^ 0-9] - 숫자가 아닌 모든 문자


^기호가 대괄호 밖에 있을 땐 - 행의 시작 부분 의미
^ 기호가 대괄호 안에 있을 땐 - 대괄호 포함 문자 제외 의미

 


 

 

[숫자] 구문 - 한정어 없는 경우


new RegExp("[123]")

또는, 

/[123]/

 

 

 

 

[숫자]  - 한정어 있는 경우


new RegExp("[123]", "g")
또는
/[123]/g

 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
DOM_Attribute JS - attr.hasAttributes() 메서드 -
DOM_Attribute JS - attr.hasChildNodes -
DOM_Attribute JS - attr.insertBefore() 메서드 -
DOM_Attribute JS - attr.isEqualNode() 메서드 -
DOM_Attribute JS - attr.isSameNode() 메서드 -
DOM_Attribute JS - attr.isSupported() 메서드 -
DOM_Attribute JS - attr.lastChild -
DOM_Attribute JS - attr.nextSibling -
DOM_Attribute JS - attr.nodeName - 사용금지 (※ 대신, attr.name 사용)
DOM_Element JS - attr.nodeType -
DOM_Attribute JS - attr.nodeValue -
DOM_Attribute JS - attr.normalize() 메서드 - 사용금지
DOM_Attribute JS - attr.ownerDocument -
DOM_Attribute JS - attr.ownerElement -
DOM_Attribute JS - attr.parentNode -
DOM_Attribute JS - attr.previousSibling -
DOM_Attribute JS - attr.removeChild -
DOM_Attribute JS - attr.replaceChild -
DOM_Attribute JS - attr.textContent -
Basic JS - const (컨스트 = 콘스트) ★★★★★ - 재할당 불가한 변수선언
21/67
목록
찾아주셔서 감사합니다. Since 2012