You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 9-regular-expressions/17-regexp-methods/article.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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).
2
4
3
-
In this article we'll cover various methods that work with regexps in-depth.
4
5
5
6
## str.match(regexp)
6
7
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
+
8
10
9
-
It has 3 modes:
11
+
Elle dispose de 3 modes:
10
12
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):
12
14
13
15
```js run
14
16
let str ="I love JavaScript";
@@ -24,7 +26,8 @@ It has 3 modes:
24
26
alert( result.input ); // I love JavaScript (source string)
25
27
```
26
28
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
+
28
31
```js run
29
32
let str = "I love JavaScript";
30
33
@@ -34,9 +37,9 @@ It has 3 modes:
34
37
alert( result.length ); // 1
35
38
```
36
39
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é.
38
41
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.:
40
43
41
44
```js run
42
45
let str = "I love JavaScript";
@@ -47,7 +50,7 @@ It has 3 modes:
47
50
alert(result.length); // Error: Cannot read property 'length' of null
48
51
```
49
52
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:
0 commit comments