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.
La propriété flags
renvoie une chaîne de caractères contenant les drapeaux (flags) de l'objet RegExp
auquel elle appartient.
Exemple interactif
// Outputs RegExp flags in alphabetical order
console.log(/foo/gi.flags);
// Expected output: "gi"
console.log(/bar/muy.flags);
// Expected output: "muy"
Attributs de RegExp.prototype.flags | |
---|---|
Écrivable | Non |
Énumérable | Non |
Configurable | Oui |
Description
Les drapeaux de la propriété flags
sont rangés par ordre alphabétique de gauche à droite.
Exemples
Utiliser flags
js
/toto/gi.flags; // "gi"
/truc/muy.flags; // "muy"
Prothèse d'émulation (polyfill)
js
if (RegExp.prototype.flags === undefined) {
Object.defineProperty(RegExp.prototype, "flags", {
configurable: true,
get: function () {
return this.toString().match(/[gimuy]*$/)[0];
},
});
}
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-get-regexp.prototype.flags |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
flags |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.