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 July 2015.

flags 접근자 속성은 현재 정규식 객체의 플래그를 나타냅니다.

시도해보기

// 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는 문자열입니다. flags 속성의 플래그는 왼쪽에서 오른쪽으로 알파벳 순으로 정렬됩니다(예를 들어 "dgimsuy"). 실제로 다른 플래그 접근자(hasIndices, global, 등등)를 하나씩 호출하고 결과를 연결합니다.

내장된 모든 함수는 개별 플래그 접근자를 읽는 대신 flags 속성을 읽습니다.

flags의 set 접근자는 정의되지 않았습니다. 이 속성을 직접 변경할 수 없습니다.

예제

flags 사용하기

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

명세서

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

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
flags

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

같이 보기