RegExp.prototype.flags
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.
尝试一下
// Outputs RegExp flags in alphabetical order
console.log(/foo/gi.flags);
// Expected output: "gi"
console.log(/bar/muy.flags);
// Expected output: "muy"
描述
RegExp.prototype.flags
具有一个字符串值。flags
属性中的标志按字母顺序排列(从左到右,例如 "dgimsuvy"
)。它实际上调用了其他标志访问器(如 hasIndices
、global
等)并逐个连接这些结果。
所有内置函数都是读取 flags
属性,而不是读取单独的标志访问器。
flags
的 set 访问器是 undefined
。因此你不能直接修改该属性。
示例
使用 flags
js
/foo/gi.flags; // "gi"
/bar/muy.flags; // "muy"
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-get-regexp.prototype.flags |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
flags |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.