CKTIS / JavaScript
RegExp.prototype.flags — reading regular expression flags
The flags property returns a regular expression's flags as a string in a fixed order, regardless of their order at creation. It is an accessor without a setter, not a method.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
regexp.flagsRegExp.prototype.flags is an accessor property read as regexp.flags, without call parentheses. It returns a string containing the enabled flags; when there are none, the result is the empty string "". It does not return the pattern or its surrounding slashes.
Letters are returned in the fixed order dgimsuvy, omitting disabled flags, rather than in their written order. The getter reads hasIndices, global, ignoreCase, multiline, dotAll, unicode, unicodeSets, and sticky in sequence, corresponding to those letters. Read values are converted to booleans. Support for flags itself does not establish support for every newer flag in a particular engine.
The accessor has no setter: assigning to regexp.flags does not change the expression's flags; for an ordinary instance in strict mode, it throws TypeError. To use different flags, create a new expression, for example new RegExp(regexp.source, "g"). The getter reads public properties, so overriding them can change the reported result without changing matching behavior.
The example demonstrates order normalization: /cat/mi returns im. JSON.stringify makes the empty string returned for /cat/ visible as "".
Examples
const regexp = /cat/mi;
console.log(regexp.flags);
console.log(JSON.stringify(/cat/.flags));Result
im ""
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.