RegExp.prototype.global

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

概述

global 属性表明正则表达式是否使用了 "g" 标志。global 是一个正则表达式实例的只读属性。

RegExp.prototype.global 的属性特性
可写
可枚举
可配置

描述

global 的值是布尔对象,如果使用了 "g" 标志,则返回 true;否则返回 false。 "g" 标志意味着正则表达式应该测试字符串中所有可能的匹配。

你无法直接更改此属性。

示例

示例:使用 global

js
var regex = new RegExp("foo", "g");

console.log(regex.global); // true

规范

Specification
ECMAScript® 2025 Language Specification
# sec-get-regexp.prototype.global

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
global
Prototype accessor property (ES2015)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见