Skip to content

Commit 1d8500d

Browse files
authored
Merge pull request #197 from Aakodal/patch-5
Anchors: string start ^ and end $
2 parents 63f2df1 + cec8de9 commit 1d8500d

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
An empty string is the only match: it starts and immediately finishes.
1+
Une chaîne de caractères vide est la seule correspondance : elle commence et se termine aussitôt.
22

3-
The task once again demonstrates that anchors are not characters, but tests.
3+
Cette tâche montre à nouveau que les ancres ne sont pas des caractères, mais des tests.
44

5-
The string is empty `""`. The engine first matches the `pattern:^` (input start), yes it's there, and then immediately the end `pattern:$`, it's here too. So there's a match.
5+
La chaîne de caractères est vide `""`. Le moteur regarde en premier `pattern:^` (début de l'entrée), ça correspond, et immédiatement après la fin `pattern:$`, ça correspond également. Donc il y a une correspondance.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Regexp ^$
22

3-
Which string matches the pattern `pattern:^$`?
3+
Quelle chaîne de caractères correspond à `pattern:^$` ?
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Anchors: string start ^ and end $
1+
# Ancres : début ^ et fin $ d'une chaîne de caractères
22

3-
The caret `pattern:^` and dollar `pattern:$` characters have special meaning in a regexp. They are called "anchors".
3+
L'accent circonflexe `pattern:^` et le signe dollar `pattern:$` ont une signification particulière dans une regexp. Ils sont appelés "ancres".
44

5-
The caret `pattern:^` matches at the beginning of the text, and the dollar `pattern:$` -- at the end.
5+
L'accent circonflexe `pattern:^` correspond au début du texte, et le signe dollar `pattern:$` -- à la fin.
66

7-
For instance, let's test if the text starts with `Mary`:
7+
Par exemple, testons si le texte commence par `Mary`:
88

99
```js run
1010
let str1 = "Mary had a little lamb";
1111
alert( /^Mary/.test(str1) ); // true
1212
```
1313

14-
The pattern `pattern:^Mary` means: "string start and then Mary".
14+
Le paterne `pattern:^Mary` signifie : "le texte commence puis Mary".
1515

16-
Similar to this, we can test if the string ends with `snow` using `pattern:snow$`:
16+
Similairement, nous pouvons vérifier si le texte termine par `snow` en utilisant `pattern:snow$`:
1717

1818
```js run
1919
let str1 = "it's fleece was white as snow";
@@ -22,13 +22,13 @@ alert( /snow$/.test(str1) ); // true
2222

2323
In these particular cases we could use string methods `startsWith/endsWith` instead. Regular expressions should be used for more complex tests.
2424

25-
## Testing for a full match
25+
## Test pour une correspondance complète
2626

27-
Both anchors together `pattern:^...$` are often used to test whether or not a string fully matches the pattern. For instance, to check if the user input is in the right format.
27+
Les deux ancres mises ensemble `pattern:^...$` pour vérifier si une chaîne de caractères correspond entièrement à un paterne. Par exemple, pour vérifier si l'entrée de l'utilisateur est dans le bon format.
2828

29-
Let's check whether or not a string is a time in `12:34` format. That is: two digits, then a colon, and then another two digits.
29+
Vérifions si une chaîne de caractères est une heure au format `12:34`. En résumé : deux nombres, puis deux points, et enfin deux autres nombres.
3030

31-
In regular expressions language that's `pattern:\d\d:\d\d`:
31+
Dans le langage des expressions régulières, c'est `pattern:\d\d:\d\d`:
3232

3333
```js run
3434
let goodInput = "12:34";
@@ -39,14 +39,14 @@ alert( regexp.test(goodInput) ); // true
3939
alert( regexp.test(badInput) ); // false
4040
```
4141

42-
Here the match for `pattern:\d\d:\d\d` must start exactly after the beginning of the text `pattern:^`, and the end `pattern:$` must immediately follow.
42+
Ici, la correspondance pour `pattern:\d\d:\d\d` doit commencer juste après le début du texte `pattern:^`, et la fin `pattern:$` doit immédiatement suivre.
4343

44-
The whole string must be exactly in this format. If there's any deviation or an extra character, the result is `false`.
44+
La chaîne entière doit être dans ce format. S'il y a la moindre déviation ou le moindre caractère de trop, le résultat sera `false`.
4545

46-
Anchors behave differently if flag `pattern:m` is present. We'll see that in the next article.
46+
Les ancres agissent différemment si le marqueur `pattern:m` est présent. Nous verrons cela dans le prochain article.
4747

48-
```smart header="Anchors have \"zero width\""
49-
Anchors `pattern:^` and `pattern:$` are tests. They have zero width.
48+
```smart header="Les ancres n'ont \"aucune longueur\""
49+
Les ancres `pattern:^` et `pattern:$` sont des tests. Elles n'ont aucune longueur.
5050
51-
In other words, they do not match a character, but rather force the regexp engine to check the condition (text start/end).
51+
En d'autres termes, elles ne vérifient pas un caractère, mais forcent plutôt le moteur à vérifier une condition (le texte commence/termine).
5252
```

0 commit comments

Comments
 (0)