multiline 속성

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

rgExp.multiline

인수

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

설명

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

multilinefalse이면 "^"는 문자열의 시작 위치와 일치하고 "$"는 문자열의 끝 위치와 일치합니다. multlinetrue이면 "^"는 "\n" 또는 "\r" 다음 위치 및 문자열의 시작 위치와 일치하고 "$"는 문자열의 끝 위치 및 "\n" 또는 "\r" 앞 위치와 일치합니다.

예제

다음 예제에서는 multiline 속성의 동작을 보여 줍니다. 아래 표시된 함수에 m을 전달하면 단어 "while"이 단어 "and"로 대체됩니다. 이는 multiline 플래그가 설정되었고 줄 바꿈 문자 뒤의 줄의 시작 부분에 단어 "while"이 있기 때문입니다. multiline 플래그를 사용하면 여러 줄 문자열에서 검색을 수행할 수 있습니다.

function RegExpMultilineDemo(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 ss = "The man hit the ball with the bat ";
    ss += "\nwhile the fielder caught the ball with the glove.";

    // Replace "while" with "and".
    var re = new RegExp("^while", flag);
    var r = ss.replace(re, "and");

    // Output the multiline flag and the resulting string.
    var s = "";
    s += "Result for multiline = " + re.multiline.toString();
    s += ": " + r;

    return(s);
}

print (RegExpMultilineDemo("m"));
print (RegExpMultilineDemo(""));

요구 사항

버전 5.5

적용 대상

Regular Expression 개체

참고 항목

참조

global 속성

ignoreCase 속성

개념

정규식 구문