RegExp.prototype.flags

The flags property returns a string consisting of the flags of the current regular expression object.

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").

Examples

Using flags

/foo/ig.flags;   // "gi"
/bar/myu.flags;  // "muy"

Polyfill

if (RegExp.prototype.flags === undefined) {
  Object.defineProperty(RegExp.prototype, 'flags', {
    configurable: true,
    get: function() {
      return this.toString().match(/[gimsuy]*$/)[0];
    }
  });
}

Specifications

Specification Status Comment
ECMAScript Latest Draft (ECMA-262)
The definition of 'RegExp.prototype.flags' in that specification.
Draft
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'RegExp.prototype.flags' in that specification.
Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
flagsChrome Full support 49Edge No support NoFirefox Full support 37IE No support NoOpera Full support 39Safari Full support YesWebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 37Opera Android Full support 41Safari iOS Full support YesSamsung Internet Android Full support 5.0nodejs Full support 6.0.0

Legend

Full support  
Full support
No support  
No support

See also