RegExp.prototype.flags
La propriété flags renvoie une chaîne de caractères contenant les drapeaux (flags) de l'objet RegExp auquel elle appartient.
Exemple interactif
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/ig.flags; // "gi"
/truc/myu.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 Language Specification # sec-get-regexp.prototype.flags |
Compatibilité des navigateurs
BCD tables only load in the browser