RegExp.prototype.flags
flags プロパティは、現在の正規表現オブジェクトのフラグから成る文字列を返します。
試してみましょう
RegExp.prototype.flags のプロパティ属性 |
|
|---|---|
| 書込可能 | 不可 |
| 列挙可能 | 不可 |
| 設定可能 | 可 |
解説
flags プロパティのフラグはアルファベット順にソートされます(左から右へ 例えば、"gimuy")。
例
flags の使用
js
/foo/ig.flags; // "gi"
/bar/myu.flags; // "muy"
ポリフィル
js
if (RegExp.prototype.flags === undefined) {
Object.defineProperty(RegExp.prototype, 'flags', {
configurable: true,
get: function() {
return this.toString().match(/[gimsuy]*$/)[0];
}
});
}
仕様書
| Specification |
|---|
| ECMAScript Language Specification # sec-get-regexp.prototype.flags |
ブラウザーの互換性
BCD tables only load in the browser