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

[RegExp] JS - [abc] 의미 - 대괄호안에 포함된 모든 개별 문자 찾기 (정규표현식 대괄호)

[ ]  대괄호 예제

 

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


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


<script>

function test() {

    var str = "Homzzang.com is a best homepage.?";

    var patt = /[hom]/g

    var result = str.match(patt);

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

}

</script>



결과 보기

 

 

 

[ ]  대괄호 정의 및 사용법


1.
대괄호안에 포함된 모든 개별 문자 찾기

2.

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


[abcde ..] - 대괄호 안의 모든 문자

[AZ] - 대문자 A에서 대문자 Z까지의 모든 문자

[az] - 소문자 a에서 소문자 z까지의 모든 문자

[Az] - 대문자 A에서 소문자 z까지의 모든 문자


cf.
[^ abc]- 대괄호 안에 없는 모든 문자

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

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

 

 

 

 

[ ]  대괄호 구문 - 한정어 없는 경우


new RegExp("[abc]")


또는,

 

/[abc]/

 

 

 

 

[ ]  대괄호 구문 - 한정어 있는 경우


new RegExp("[abc]", "g")

또는,

/[abc]/g

 

 


분류 제목
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