RegExp.prototype.flags
试一试
// 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 的设置访问器为 undefined。您不能直接更改此属性。
示例
使用标志
js
/foo/ig.flags; // "gi"
/^bar/myu.flags; // "muy"
规范
| 规范 |
|---|
| ECMAScript® 2026 语言规范 # sec-get-regexp.prototype.flags |
浏览器兼容性
加载中…