This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The flags accessor property of RegExp instances returns the flags of this regular expression.
// Outputs RegExp flags in alphabetical order console.log(/foo/gi.flags); // Expected output: "gi" console.log(/^bar/muy.flags); // Expected output: "muy"
RegExp.prototype.flags has a string as its value. Flags in the flags property are sorted alphabetically (from left to right, e.g., "dgimsuvy"). It actually invokes the other flag accessors (hasIndices, global, etc.) one-by-one and concatenates the results.
All built-in functions read the flags property instead of reading individual flag accessors.
The set accessor of flags is undefined. You cannot change this property directly.
/foo/ig.flags; // "gi" /^bar/myu.flags; // "muy"
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
flags |
49 | 79 | 37 | 39 | 9 | 49 | 37 | 41 | 9 | 5.0 | 49 | 9 | 1.0.0 | 1.0 | 6.0.0 |
RegExp.prototype.flags in core-jsRegExp.prototype.flagsRegExp.prototype.source
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags