目录

RegExp.prototype.global

global是RegExp对象的只读布尔属性。 它指定特定正则表达式是否执行全局匹配,即是否使用“g”属性创建。

语法 (Syntax)

RegExpObject.global        

返回值 (Return Value)

如果设置“g”修饰符则返回“TRUE”,否则返回“FALSE”。

例子 (Example)

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");  
}          

输出 (Output)

Test1 - Global property is not set 
Test2 - Global property is set       
↑回到顶部↑
WIKI教程 @2018