Skip to content

Commit 7cfebf8

Browse files
committed
[WIP]regexpMethods(french trad) - str.match(regexp) traduction done
1 parent bdd2bf7 commit 7cfebf8

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

9-regular-expressions/17-regexp-methods/article.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# Methods of RegExp and String
1+
# Methodes des Expressions Regulières et des chaînes de caractères
2+
3+
Dans cet article, nous aborderons différentes méthodes qui fonctionnent en profondeur avec des expressions regulieres (regexps).
24

3-
In this article we'll cover various methods that work with regexps in-depth.
45

56
## str.match(regexp)
67

7-
The method `str.match(regexp)` finds matches for `regexp` in the string `str`.
8+
La méthode `str.match(regexp)` trouve les correspondances de l'expression reguliere `regexp` dans le texte `str`.
9+
810

9-
It has 3 modes:
11+
Elle dispose de 3 modes :
1012

11-
1. If the `regexp` doesn't have flag `pattern:g`, then it returns the first match as an array with capturing groups and properties `index` (position of the match), `input` (input string, equals `str`):
13+
1. si la regexpn'à pas de marqueur pattern:g, alors seul la première correspondance est retournée sous la forme d'un tableau avec le groupe capturé et ses propriétés index (position de la correspondance), et input (chaîne d'entrée équivalent à str):
1214

1315
```js run
1416
let str = "I love JavaScript";
@@ -24,7 +26,8 @@ It has 3 modes:
2426
alert( result.input ); // I love JavaScript (source string)
2527
```
2628

27-
2. If the `regexp` has flag `pattern:g`, then it returns an array of all matches as strings, without capturing groups and other details.
29+
2. Si la `regexp` dispose d'un marqueur `pattern:g`, alors elle retourne un tableau de toutes les correspondances de texte, sans capturer les groupes ou les autres propriétés.
30+
2831
```js run
2932
let str = "I love JavaScript";
3033
@@ -34,9 +37,9 @@ It has 3 modes:
3437
alert( result.length ); // 1
3538
```
3639
37-
3. If there are no matches, no matter if there's flag `pattern:g` or not, `null` is returned.
40+
3. S'il n'y a pas de correspondance, qu'il y ait un marqueur `pattern:g` ou non, `null` est retourné.
3841

39-
That's an important nuance. If there are no matches, we don't get an empty array, but `null`. It's easy to make a mistake forgetting about it, e.g.:
42+
C'est une nuance importante. Si il n'y a pas de correspondance, nous ne récupérons pas un tableau vide, mais `null`. Il n'est pas rare de faire une erreur en oubliant ce détail, e.g.:
4043
4144
```js run
4245
let str = "I love JavaScript";
@@ -47,7 +50,7 @@ It has 3 modes:
4750
alert(result.length); // Error: Cannot read property 'length' of null
4851
```
4952
50-
If we want the result to be an array, we can write like this:
53+
Si nous voulons que le résultat soit un tableau, nous pouvons écrire de cette façon:
5154
5255
```js
5356
let result = str.match(regexp) || [];

0 commit comments

Comments
 (0)