Web/JavaScript/Reference/Global objects/RegExp/flags

From Get docs


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
ECMAScript (ECMA-262)The definition of 'RegExp.prototype.flags' in that specification.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
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


See also