The flags
property returns a string consisting of the flags of the current regular expression object.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Property attributes of RegExp.prototype.flags |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | yes |
Description
Flags in the flags
property are sorted alphabetically (from left to right, e.g. "gimsuy"
).
Polyfill
if (RegExp.prototype.flags === undefined) { Object.defineProperty(RegExp.prototype, 'flags', { configurable: true, get: function() { return this.toString().match(/[gimsuy]*$/)[0]; } }); }
Examples
Using flags
/foo/ig.flags; // "gi" /bar/myu.flags; // "muy"
Specifications
Specification |
---|
ECMAScript (ECMA-262) The definition of 'RegExp.prototype.flags' in that specification. |
Browser compatibility
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.
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
flags | Chrome Full support 49 | Edge Full support 79 | Firefox Full support 37 | IE No support No | Opera Full support 39 | Safari Full support 9 | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 37 | Opera Android Full support 41 | Safari iOS Full support 9 | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0 |
Legend
- Full support
- Full support
- No support
- No support