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
Le mode multiligne est activé avec le marqueur`pattern:m`.
3
+
The multiline mode is enabled by the flag`pattern:m`.
4
4
5
-
Il affecte seulement le fonctionnement des ancres `pattern:^`et`pattern:$`.
5
+
It only affects the behavior of `pattern:^`and`pattern:$`.
6
6
7
-
Dans le mode multiligne, elles ne vérifient pas seulement le début et la fin d'une chaîne de caractères, mais également le début et la fin d'une ligne.
7
+
In the multiline mode they match not only at the beginning and the end of the string, but also at start/end of line.
8
8
9
-
## Recherche au début de ligne ^
9
+
## Searching at line start ^
10
10
11
-
Dans l'exemple ci-dessous, le texte comporte plusieurs lignes. Le paterne`pattern:/^\d/gm`prend un chiffre au début de chaque ligne:
11
+
In the example below the text has multiple lines. The pattern`pattern:/^\d/gm`takes a digit from the beginning of each line:
Cela est dû au fait que, par défaut, l'accent circonflexe `pattern:^`ne vérifie que le début d'un texte, et dans le mode multiligne -- le début de n'importe quelle ligne.
35
+
That's because by default a caret `pattern:^`only matches at the beginning of the text, and in the multiline mode -- at the start of any line.
36
36
37
37
```smart
38
-
"Début de ligne" désigne formellement "immédiatement après un saut à la ligne" : le test `pattern:^` en mode multiligne vérifie à toutes les positions suivant un caractère de retour à la ligne `\n`, en plus du début du texte.
38
+
"Start of a line" formally means "immediately after a line break": the test `pattern:^` in multiline mode matches at all positions preceeded by a newline character `\n`.
39
+
40
+
And at the text start.
39
41
```
40
42
41
-
## Recherche en fin de ligne $
43
+
## Searching at line end $
42
44
43
-
Le signe dollar `pattern:$`se comporte similairement.
45
+
The dollar sign `pattern:$`behaves similarly.
44
46
45
-
L'expression régulière `pattern:\d$`prend le premier chiffre à la fin de chaque ligne.
47
+
The regular expression `pattern:\d$`finds the last digit in every line
46
48
47
49
```js run
48
50
let str =`Winnie: 1
@@ -52,19 +54,21 @@ Eeyore: 3`;
52
54
alert( str.match(/\d$/gm) ); // 1,2,3
53
55
```
54
56
55
-
Sans le marqueur `pattern:m`, le signe dollar `pattern:$`vérifierait uniquement la fin de tout le texte, donc uniquement le tout dernier chiffre serait trouvé.
57
+
Without the flag `m`, the dollar `pattern:$`would only match the end of the whole text, so only the very last digit would be found.
56
58
57
59
```smart
58
-
"Fin de ligne" désigne formellement "immédiatement avant un saut à la ligne" : le test `pattern:$` en mode multiligne vérifie à toutes les positions précédant un caractère de retour à la ligne `\n`, en plus de la fin du texte.
60
+
"End of a line" formally means "immediately before a line break": the test `pattern:$` in multiline mode matches at all positions succeeded by a newline character `\n`.
61
+
62
+
And at the text end.
59
63
```
60
64
61
-
## Recherche de \n au lieu de ^ $
65
+
## Searching for \n instead of ^ $
62
66
63
-
Pour chercher un retour à la ligne, nous pouvons non seulement utiliser les ancres `pattern:^`et`pattern:$`, mais également le caractère de retour à la ligne`\n`.
67
+
To find a newline, we can use not only anchors `pattern:^`and`pattern:$`, but also the newline character`\n`.
64
68
65
-
Quelle est la différence ? Regardons un exemple.
69
+
What's the difference? Let's see an example.
66
70
67
-
Ici, nous cherchons `pattern:\d\n`au lieu de`pattern:\d$`:
71
+
Here we search for `pattern:\d\n`instead of`pattern:\d$`:
68
72
69
73
```js run
70
74
let str =`Winnie: 1
@@ -74,10 +78,10 @@ Eeyore: 3`;
74
78
alert( str.match(/\d\n/gm) ); // 1\n,2\n
75
79
```
76
80
77
-
Comme nous pouvons le voir, il y a 2 correspondances au lieu de 3.
81
+
As we can see, there are 2 matches instead of 3.
78
82
79
-
C'est parce qu'il n'y a pas de retour à la ligne après `subject:3` (il y a la fin du texte cependant, donc ça correspond avec`pattern:$`).
83
+
That's because there's no newline after `subject:3` (there's text end though, so it matches`pattern:$`).
80
84
81
-
Une autre différence : maintenant, chaque correspondance inclue un caractère de retour à la ligne `match:\n`. Contrairement aux ancres`pattern:^``pattern:$`, qui ne testent qu'une condition (début/fin d'une ligne), `\n`est un caractère, donc il devient une partie du résultat.
85
+
Another difference: now every match includes a newline character `match:\n`. Unlike the anchors`pattern:^``pattern:$`, that only test the condition (start/end of a line), `\n`is a character, so it becomes a part of the result.
82
86
83
-
Ainsi, un`\n`dans le paterne est utilisé quand nous avons besoin dudit caractère dans le résultat, tandis que les ancres sont utilisées pour chercher quelque chose au début/à la fin d'une ligne.
87
+
So, a`\n`in the pattern is used when we need newline characters in the result, while anchors are used to find something at the beginning/end of a line.
0 commit comments