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/string/search/index.html | 103 --------------------- 1 file changed, 103 deletions(-) delete mode 100644 files/fr/web/javascript/reference/global_objects/string/search/index.html (limited to 'files/fr/web/javascript/reference/global_objects/string/search/index.html') diff --git a/files/fr/web/javascript/reference/global_objects/string/search/index.html b/files/fr/web/javascript/reference/global_objects/string/search/index.html deleted file mode 100644 index aa1828528f..0000000000 --- a/files/fr/web/javascript/reference/global_objects/string/search/index.html +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: String.prototype.search() -slug: Web/JavaScript/Reference/Global_Objects/String/search -tags: - - Expressions rationnelles - - JavaScript - - Méthode - - Prototype - - Reference - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/search -original_slug: Web/JavaScript/Reference/Objets_globaux/String/search ---- -
{{JSRef}}
- -

La méthode search() éxecute une recherche dans une chaine de caractères grâce à une expression rationnelle appliquée sur la chaîne courante.

- -
{{EmbedInteractiveExample("pages/js/string-search.html")}}
- -

Syntaxe

- -
str.search(regexp)
- -

Paramètres

- -
-
regexp
-
Un objet représentant une expression rationnelle. Si l'objet passé n'est pas un objet d'expression régulière, il est directement converti en une instance de {{jsxref("RegExp")}} en utilisant new RegExp(obj).
-
- -

Valeur de retour

- -

Si la recherche aboutit, search() renvoie un entier qui correspond à l'indice de la première correspondance trouvée dans la chaîne. Si rien n'est trouvé, la méthode renvoie -1.

- -

Description

- -

Si la recherche est positive, search() renvoie l'indice de la première correspondance pour l'expression rationnelle au sein de la chaine de caractères. Sinon, la méthode renvoie -1.

- -

Si on souhaite savoir si un motif est trouvé dans une chaine de caractères, on utilisera cette méthode (semblable à la méthode {{jsxref("RegExp.prototype.test", "test()")}}) du prototype de RegExp ; pour plus d'informations (mais une éxecution plus lente), on utilisera {{jsxref("String.prototype.match", "match()")}} (semblable à la méthode {{jsxref("RegExp.prototype.exec", "exec()")}} pour les expressions rationnelles). La méthode test est semblable mais renvoie uniquement un booléen indiquant si une correspondance a été trouvée.

- -

Exemples

- -

Dans l'exemple suivant, on utilise une chaîne de caractères pour laquelle on applique deux expressions rationnelles (la première permet d'obtenir une correspondance et la seconde n'en trouve aucune).

- -
var maChaine = "CoucOu";
-var regex1 = /[A-Z]/g;
-var regex2 = /[.]/g;
-
-console.log(maChaine.search(regex1)); // Renvoie 0, la position de la première majuscule
-console.log(maChaine.search(regex2)); // Renvoie -1 car il n'y a aucun point dans la chaîne
- -

Spécifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES3')}}{{Spec2('ES3')}}Définition initiale. Implémentée avec JavaScript 1.2
{{SpecName('ES5.1', '#sec-15.5.4.12', 'String.prototype.search')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.search', 'String.prototype.search')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.search', 'String.prototype.search')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.String.search")}}

- -

Notes spécifiques à Gecko

- - - -

Voir aussi

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