From 844f5103992238c0c23203286dad16a466e89c97 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:09 +0200 Subject: move *.html to *.md --- .../global_objects/regexp/@@match/index.html | 116 --------------------- .../global_objects/regexp/@@match/index.md | 116 +++++++++++++++++++++ 2 files changed, 116 insertions(+), 116 deletions(-) delete mode 100644 files/fr/web/javascript/reference/global_objects/regexp/@@match/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/regexp/@@match/index.md (limited to 'files/fr/web/javascript/reference/global_objects/regexp/@@match') diff --git a/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.html b/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.html deleted file mode 100644 index 9d3c824406..0000000000 --- a/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.html +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: RegExp.prototype[@@match]() -slug: Web/JavaScript/Reference/Global_Objects/RegExp/@@match -tags: - - Expressions rationnelles - - JavaScript - - Méthode - - Prototype - - Reference - - RegExp -translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/@@match -original_slug: Web/JavaScript/Reference/Objets_globaux/RegExp/@@match ---- -
{{JSRef}}
- -

La méthode [@@match]() permet de récupérer les correspondances obtenues lorsqu'on teste une chaîne de caractères par rapport à une expression rationnelle (regexp).

- -
{{EmbedInteractiveExample("pages/js/regexp-prototype-@@match.html")}}
- -

Syntaxe

- -
regexp[Symbol.match](str)
- -

Paramètres

- -
-
str
-
La chaîne de caractères ({{jsxref("String")}}) sur laquelle on veut chercher des correspondances.
-
- -

Valeur de retour

- -

Un tableau ({{jsxref("Array")}}) qui contient les résultats des correspondances et les groupes capturés grâce aux parenthèse. S'il n'y a aucune correspondance, ce sera {{jsxref("null")}}.

- -

Description

- -

Cette méthode est appelée de façon interne lorsqu'on utilise {{jsxref("String.prototype.match()")}}. Ainsi, les deux exemples qui suivent sont équivalents et le second est la version interne du premier :

- -
'abc'.match(/a/);
-
-/a/[Symbol.match]('abc');
- -

Cette méthode existe afin de permettre d'adapter le comportement de la recherche des correspondances pour les sous-classes de RegExp.

- -

Exemples

- -

Appel direct

- -

Cette méthode peut être utilisée comme {{jsxref("String.prototype.match()")}} mais avec un objet this différent et un ordre des paramètres également différent.

- -
var re = /[0-9]+/g;
-var str = '2016-01-02';
-var résultat = re[Symbol.match](str);
-console.log(résultat);  // ["2016", "01", "02"]
-
- -

Utilisation de @@match avec une sous-classe

- -

Les sous-classes de {{jsxref("RegExp")}} peuvent surcharger la méthode [@@match]() afin de modifier le comportement.

- -
class MaRegExp extends RegExp {
-  [Symbol.match](str) {
-    var résultat = RegExp.prototype[Symbol.match].call(this, str);
-    if (!résultat) return null;
-    return {
-      group(n) {
-        return résultat[n];
-      }
-    };
-  }
-}
-
-var re = new MaRegExp('([0-9]+)-([0-9]+)-([0-9]+)');
-var str = '2016-01-02';
-var résultat = str.match(re); // String.prototype.match appelle re[@@match].
-console.log(résultat.group(1)); // 2016
-console.log(résultat.group(2)); // 01
-console.log(résultat.group(3)); // 02
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES6', '#sec-regexp.prototype-@@match', 'RegExp.prototype[@@match]')}}{{Spec2('ES6')}}Définition initiale.
{{SpecName('ESDraft', '#sec-regexp.prototype-@@match', 'RegExp.prototype[@@match]')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.RegExp.@@match")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.md b/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.md new file mode 100644 index 0000000000..9d3c824406 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/regexp/@@match/index.md @@ -0,0 +1,116 @@ +--- +title: RegExp.prototype[@@match]() +slug: Web/JavaScript/Reference/Global_Objects/RegExp/@@match +tags: + - Expressions rationnelles + - JavaScript + - Méthode + - Prototype + - Reference + - RegExp +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/@@match +original_slug: Web/JavaScript/Reference/Objets_globaux/RegExp/@@match +--- +
{{JSRef}}
+ +

La méthode [@@match]() permet de récupérer les correspondances obtenues lorsqu'on teste une chaîne de caractères par rapport à une expression rationnelle (regexp).

+ +
{{EmbedInteractiveExample("pages/js/regexp-prototype-@@match.html")}}
+ +

Syntaxe

+ +
regexp[Symbol.match](str)
+ +

Paramètres

+ +
+
str
+
La chaîne de caractères ({{jsxref("String")}}) sur laquelle on veut chercher des correspondances.
+
+ +

Valeur de retour

+ +

Un tableau ({{jsxref("Array")}}) qui contient les résultats des correspondances et les groupes capturés grâce aux parenthèse. S'il n'y a aucune correspondance, ce sera {{jsxref("null")}}.

+ +

Description

+ +

Cette méthode est appelée de façon interne lorsqu'on utilise {{jsxref("String.prototype.match()")}}. Ainsi, les deux exemples qui suivent sont équivalents et le second est la version interne du premier :

+ +
'abc'.match(/a/);
+
+/a/[Symbol.match]('abc');
+ +

Cette méthode existe afin de permettre d'adapter le comportement de la recherche des correspondances pour les sous-classes de RegExp.

+ +

Exemples

+ +

Appel direct

+ +

Cette méthode peut être utilisée comme {{jsxref("String.prototype.match()")}} mais avec un objet this différent et un ordre des paramètres également différent.

+ +
var re = /[0-9]+/g;
+var str = '2016-01-02';
+var résultat = re[Symbol.match](str);
+console.log(résultat);  // ["2016", "01", "02"]
+
+ +

Utilisation de @@match avec une sous-classe

+ +

Les sous-classes de {{jsxref("RegExp")}} peuvent surcharger la méthode [@@match]() afin de modifier le comportement.

+ +
class MaRegExp extends RegExp {
+  [Symbol.match](str) {
+    var résultat = RegExp.prototype[Symbol.match].call(this, str);
+    if (!résultat) return null;
+    return {
+      group(n) {
+        return résultat[n];
+      }
+    };
+  }
+}
+
+var re = new MaRegExp('([0-9]+)-([0-9]+)-([0-9]+)');
+var str = '2016-01-02';
+var résultat = str.match(re); // String.prototype.match appelle re[@@match].
+console.log(résultat.group(1)); // 2016
+console.log(résultat.group(2)); // 01
+console.log(résultat.group(3)); // 02
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES6', '#sec-regexp.prototype-@@match', 'RegExp.prototype[@@match]')}}{{Spec2('ES6')}}Définition initiale.
{{SpecName('ESDraft', '#sec-regexp.prototype-@@match', 'RegExp.prototype[@@match]')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.RegExp.@@match")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf