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

[RegExp] JS - [^abc] 의미 - 대괄호 안 문자 제외 (= 대괄호안 꺽쇠 정규표현식) ★ 소문자만 추출

목차
  1. [^abc] 예제 - 대괄호 안 문자에 해당 않는 문자만 출력
  2. [^abc] 정의
  3. [^abc] 구문
  4. [^abc] 예제 - 소문자만 추출

 

[^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>


결과 보기

결과값: H,z,z,a,n,g,.,c, ,i,s, ,a, ,b,e,s,t, ,e,p,a,g,e,.,? 

 

[^abc] 정의


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

 



1.

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


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

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

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

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


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

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

 

 

[^abc] 구문

[한정어 없는 경우]

 

new RegExp("[^abc]")

또는

/[^abc]/

 


[한정어 있는 경우]

 

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

 

 

[^abc] 예제 - 소문자만 추출

 

<script>

var str = "dfDASs09)(_(_)(FSFdsf0)(_(_)";

const pat = /[^a-z]/g; // 소문자 아닌 것들

 

var result = str.replace(pat, ""); // 소문자 아닌 것들 제거

document.write("소문자: " + result); // dfsdsf

</script>

 

결과보기

평정심 님 (210822) https://sir.kr/qa/427357



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