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.

必要条件

Version 5.5

対象:

Regular Expression オブジェクト

参照

参照

global プロパティ

multiline プロパティ

概念

正規表現の構文