Es6-regexp-prototype-global

提供:Dev Guides
2020年6月23日 (火) 08:04時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

ES6-RegExpグローバル

globalは、RegExpオブジェクトの読み取り専用のブールプロパティです。 特定の正規表現がグローバルマッチングを実行するかどうか、つまり「g」属性で作成されたかどうかを指定します。

構文

RegExpObject.global

戻り値

「g」修飾子が設定されている場合は「TRUE」、それ以外の場合は「FALSE」を返します。

var re = new RegExp( "string" );
if ( re.global ) {
   console.log("Test1 - Global property is set");
} else {
   console.log("Test1 - Global property is not set");
}
re = new RegExp( "string", "g" );

if ( re.global ) {
   console.log("Test2 - Global property is set");
} else {
   console.log("Test2 - Global property is not set");
}

出力

Test1 - Global property is not set
Test2 - Global property is set