Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. RegExp
  6. flags

RegExp.prototype.flags

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨January 2020⁩.

Theflags accessor property ofRegExp instances returns theflags of this regular expression.

Try it

// Outputs RegExp flags in alphabetical orderconsole.log(/foo/gi.flags);// Expected output: "gi"console.log(/^bar/muy.flags);// Expected output: "muy"

Description

RegExp.prototype.flags has a string as its value. Flags in theflags 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 theflags property instead of reading individual flag accessors.

The set accessor offlags isundefined. You cannot change this property directly.

Examples

Using flags

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

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-get-regexp.prototype.flags

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp