ignoreCase 속성

정규식에 사용된 ignoreCase 플래그(i)의 상태를 나타내는 부울 값을 반환합니다.

rgExp.ignoreCase

인수

  • rgExp
    필수적 요소로서, Regular Expression 개체의 인스턴스입니다.

설명

ignoreCase 속성은 읽기 전용이고 정규식에 ignoreCase 플래그가 설정되면 true를 반환하고 그렇지 않으면 false를 반환합니다. 기본값은 false입니다.

ignoreCase 플래그가 사용되면 검색 문자열 내에서 패턴이 일치할 경우 대소문자를 무시합니다.

예제

다음 예제는 ignoreCase 속성의 사용 예를 보여 줍니다.

다음 예제에서는 ignoreCase 속성을 사용하는 방법을 보여 줍니다. 아래 표시된 함수에 gi를 전달하면 초기 "The"를 비롯한 단어 "the"의 모든 인스턴스가 단어 "a"로 바뀝니다. 이는 ignoreCase 플래그가 설정된 경우 검색에서 대/소문자 구분을 무시하기 때문입니다. 따라서 일치 시 "T"는 "t"와 같습니다.

이 함수는 허용 가능한 정규식 플래그인 g, i 및 m의 상태를 나타내는 부울 값을 반환합니다. 또한 모든 대체가 수행된 문자열을 반환합니다.

function RegExpPropDemo(flag){
    // The flag parameter is a string that contains
    // g, i, or m.  The flags can be combined.

    // Check flags for validity.
    if (flag.match(/[^gim]/))
        {
        return ("Flag specified is not valid");
        }

    // Create the string on which to perform the replacement.
    var orig = "The batter hit the ball with the bat ";
    orig += "and the fielder caught the ball with the glove.";

    //Replace "the" with "a".
    var re = new RegExp("the", flag);
    var r = orig.replace(re, "a");        

    // Output the resulting string and the values of the flags.
    print("global: " + re.global.toString());
    print("ignoreCase: " + re.ignoreCase.toString());
    print("multiline: " + re.multiline.toString());
    print("Resulting String: " + r);
}

RegExpPropDemo("gi");
RegExpPropDemo("g");

다음은 결과 출력입니다.

global: true
ignoreCase: true
multiline: false
Resulting String: a batter hit a ball with a bat and a fielder caught a ball with a glove.

global: true
ignoreCase: false
multiline: false
Resulting String: The batter hit a ball with a bat and a fielder caught a ball with a glove.

요구 사항

버전 5.5

적용 대상

Regular Expression 개체

참고 항목

참조

global 속성

multiline 속성

개념

정규식 구문