JScript 8.0 中文手册| 首页 | asp之家
global 属性

返回布尔值,该值指示使用正则表达式的 global 标志 (g) 的状态。

rgExp.global
参数
rgExp

必选。Regular Expression 对象的一个实例。

备注

global 属性是只读的,并且如果 global 标志是为正则表达式设置的,则返回 true,否则返回 false。默认值为 false

当使用 global 标志时,它将指示一个搜索操作应找到被搜索字符串中的所有模式,而不仅仅是第一个。这也称为全局匹配。

示例

下面的示例阐释了 global 属性的用法。

function RegExpPropDemo(re : RegExp) {
   print("Regular expression: " + re);
   print("global:     " + re.global);
   print("ignoreCase: " + re.ignoreCase);
   print("multiline:  " + re.multiline);
   print();
};
// Some regular expression to test the function.
var re1 : RegExp = new RegExp("the","i");  // Use the constructor.
var re2 = /\w+/gm;                         // Use a literal.
RegExpPropDemo(re1);
RegExpPropDemo(re2);
RegExpPropDemo(/^\s*$/im);

该程序的输出为:

Regular expression: /the/i
global:     false
ignoreCase: true
multiline:  false
Regular expression: /\w+/gm
global:     true
ignoreCase: false
multiline:  true
Regular expression: /^\s*$/im
global:     false
ignoreCase: true
multiline:  true
要求

版本 5.5

应用于:

请参见

参考

ignoreCase 属性
multiline 属性

概念

正则表达式语法