Skip to content

Commit b5b6812

Browse files
committed
[WIP]RegexpMmethod(trad in french) - work done until str.search
1 parent 7cfebf8 commit b5b6812

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ La méthode `str.match(regexp)` trouve les correspondances de l'expression regul
1010

1111
Elle dispose de 3 modes :
1212

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):
13+
1. si la regexp n'à 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):
1414

1515
```js run
1616
let str = "I love JavaScript";
@@ -60,27 +60,28 @@ Elle dispose de 3 modes :
6060
6161
[recent browser="new"]
6262
63-
The method `str.matchAll(regexp)` is a "newer, improved" variant of `str.match`.
63+
La méthode `str.matchAll(regexp)` est une variante "améliorée" de `str.match`.
6464
65+
Elle est principalement utilisée pour rechercher toutes les correspondances au sein de tous les groupes.
6566
It's used mainly to search for all matches with all groups.
6667

67-
There are 3 differences from `match`:
68+
Il y a 3 différences avec `match`:
6869

69-
1. It returns an iterable object with matches instead of an array. We can make a regular array from it using `Array.from`.
70-
2. Every match is returned as an array with capturing groups (the same format as `str.match` without flag `pattern:g`).
71-
3. If there are no results, it returns not `null`, but an empty iterable object.
70+
1. Elle retourne un objet iterable avec les correspondances au lieu d'un tableau. Nous pouvons le transformer en un tableau en utilisant la méthode `Array.from`.
71+
2. Toutes les correspondances sont retournées dans un tableau incluant les groupes capturants (sous le même format que `str.match` sans le marqueur `pattern:g`).
72+
3. Si aucun résultat, `null` n'est pas retourné, mais un objet itérable vide.
7273

73-
Usage example:
74+
Exemple d'utilisation:
7475
7576
```js run
7677
let str = '<h1>Hello, world!</h1>';
7778
let regexp = /<(.*?)>/g;
7879
7980
let matchAll = str.matchAll(regexp);
8081
81-
alert(matchAll); // [object RegExp String Iterator], not array, but an iterable
82+
alert(matchAll); // [object RegExp String Iterator], pas un tableau, mais un itérateur
8283
83-
matchAll = Array.from(matchAll); // array now
84+
matchAll = Array.from(matchAll); // maintenant un tableau
8485
8586
let firstMatch = matchAll[0];
8687
alert( firstMatch[0] ); // <h1>
@@ -89,37 +90,37 @@ alert( firstMatch.index ); // 0
8990
alert( firstMatch.input ); // <h1>Hello, world!</h1>
9091
```
9192
92-
If we use `for..of` to loop over `matchAll` matches, then we don't need `Array.from` any more.
93+
Si nous utilisons `for..of` pour boucler sur les résultats de `matchAll`, alors `Array.from` n'est plus utile.
9394

9495
## str.split(regexp|substr, limit)
9596

96-
Splits the string using the regexp (or a substring) as a delimiter.
97+
Diviser la chaîne de caractères en utilisant la regexp (ou une sous-chaîne de caractères) comme délimiteur.
9798

98-
We can use `split` with strings, like this:
99+
Nous pouvons utiliser `split` avec un chaîne de caractères comme ceci :
99100

100101
```js run
101102
alert('12-34-56'.split('-')) // array of [12, 34, 56]
102103
```
103104

104-
But we can split by a regular expression, the same way:
105+
Mais nous pouvons aussi diviser une chaîne de texte en utilisant une expression regulière:
105106

106107
```js run
107108
alert('12, 34, 56'.split(/,\s*/)) // array of [12, 34, 56]
108109
```
109110

110111
## str.search(regexp)
111112

112-
The method `str.search(regexp)` returns the position of the first match or `-1` if none found:
113+
La méthode `str.search(regexp)` renvoie la position du premier motif correspondant, ou `-1` si aucune correspondance n'est trouvée:
113114
114115
```js run
115116
let str = "A drop of ink may make a million think";
116117
117-
alert( str.search( /ink/i ) ); // 10 (first match position)
118+
alert( str.search( /ink/i ) ); // 10 (position du premier motif correspondant)
118119
```
119120
120-
**The important limitation: `search` only finds the first match.**
121+
**Limitation importante: `search` renvoie uniquement la première correspondance.**
121122
122-
If we need positions of further matches, we should use other means, such as finding them all with `str.matchAll(regexp)`.
123+
Si nous avons besoin de la position ou de plus de correspondances, nous devrions utiliser d'autres méthodes, comme les trouver tous avec `str.matchAll(regexp)`.
123124

124125
## str.replace(str|regexp, str|func)
125126

0 commit comments

Comments
 (0)