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

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

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
flagsChrome Full support 49Edge Full support 79Firefox Full support 37IE No support NoOpera Full support 39Safari Full support 9WebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 37Opera Android Full support 41Safari iOS Full support 9Samsung Internet Android Full support 5.0nodejs Full support 6.0.0

Legend

Full support
Full support
No support
No support

See also