diff --git a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md index e33f9cf2f..e80615f2d 100644 --- a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md +++ b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md @@ -1,7 +1,7 @@ -The first idea can be to list the languages with `|` in-between. +La première idée peut être de lister les langages avec des `|` entre deux. -But that doesn't work right: +Mais cela ne fonctionne pas correctement : ```js run let regexp = /Java|JavaScript|PHP|C|C\+\+/g; @@ -11,18 +11,18 @@ let str = "Java, JavaScript, PHP, C, C++"; alert( str.match(regexp) ); // Java,Java,PHP,C,C ``` -The regular expression engine looks for alternations one-by-one. That is: first it checks if we have `match:Java`, otherwise -- looks for `match:JavaScript` and so on. +Le moteur d'expression régulière regarde les alternances une par une. C'est-à-dire : il regarde d'abord si nous avons `match:Java`, sinon il recherche `match:JavaScript` et ainsi de suite. -As a result, `match:JavaScript` can never be found, just because `match:Java` is checked first. +Ainsi, `match:JavaScript` ne peut jamais être trouvé, puisque `match:Java` est vérifié en premier. -The same with `match:C` and `match:C++`. +Pareil pour `match:C` et `match:C++`. -There are two solutions for that problem: +Il y a deux solutions à ce problème : -1. Change the order to check the longer match first: `pattern:JavaScript|Java|C\+\+|C|PHP`. -2. Merge variants with the same start: `pattern:Java(Script)?|C(\+\+)?|PHP`. +1. Changer l'ordre pour vérifier le mot le plus long en premier : `pattern:JavaScript|Java|C\+\+|C|PHP`. +2. Fusionner les mots commençant de la même manière : `pattern:Java(Script)?|C(\+\+)?|PHP`. -In action: +En action : ```js run let regexp = /Java(Script)?|C(\+\+)?|PHP/g; diff --git a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md index e0f7af95c..7e037ef47 100644 --- a/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md +++ b/9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md @@ -1,8 +1,8 @@ -# Find programming languages +# Trouver les langages de programmation -There are many programming languages, for instance Java, JavaScript, PHP, C, C++. +Il y a beaucoup de langages de programmation, par exemple Java, JavaScript, PHP, C, C++. -Create a regexp that finds them in the string `subject:Java JavaScript PHP C++ C`: +Créez une regexp qui les trouve dans une chaine de caractère `subject:Java JavaScript PHP C++ C` : ```js let regexp = /your regexp/g; diff --git a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md index 9b3fa1877..c20da5b75 100644 --- a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md +++ b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md @@ -1,11 +1,11 @@ -Opening tag is `pattern:\[(b|url|quote)\]`. +Un tag d'ouverture correspond à `pattern:\[(b|url|quote)\]`. -Then to find everything till the closing tag -- let's use the pattern `pattern:.*?` with flag `pattern:s` to match any character including the newline and then add a backreference to the closing tag. +Ensuite pour trouver tout jusqu'au tag de fermeture, utilisons le modèle `pattern:.*?` avec le flag `pattern:s` pour trouver n'importe quel caractère en plus des sauts de ligne, puis ajoutons une référence au tag de fermeture. -The full pattern: `pattern:\[(b|url|quote)\].*?\[/\1\]`. +Le modèle : `pattern:\[(b|url|quote)\].*?\[/\1\]`. -In action: +En action : ```js run let regexp = /\[(b|url|quote)\].*?\[\/\1\]/gs; @@ -20,4 +20,4 @@ let str = ` alert( str.match(regexp) ); // [b]hello![/b],[quote][url]http://google.com[/url][/quote] ``` -Please note that besides escaping `pattern:[` and `pattern:]`, we had to escape a slash for the closing tag `pattern:[\/\1]`, because normally the slash closes the pattern. +Veuillez noter qu'en plus de `pattern:[` et `pattern:]`, nous avons dû échapper un slash pour le tag de fermeture `pattern:[\/\1]` puisque normalement un slash ferme le modèle. diff --git a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md index 72d715afd..1a0a5c8fb 100644 --- a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md +++ b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md @@ -1,25 +1,25 @@ -# Find bbtag pairs +# Trouver les paires de bbtag -A "bb-tag" looks like `[tag]...[/tag]`, where `tag` is one of: `b`, `url` or `quote`. +Un "bb-tag" ressemble à `[tag]...[/tag]`, où `tag` peut être : `b`, `url` ou `quote`. -For instance: +Par exemple : ``` [b]text[/b] [url]http://google.com[/url] ``` -BB-tags can be nested. But a tag can't be nested into itself, for instance: +Les BB-tags peuvent être imbriqués. Mais un tag ne peut pas être imbriqué dans lui même, par exemple : ``` Normal: [url] [b]http://google.com[/b] [/url] [quote] [b]text[/b] [/quote] -Can't happen: +Ne peut pas arriver: [b][b]text[/b][/b] ``` -Tags can contain line breaks, that's normal: +Les tags peuvent contenir des sauts de ligne, c'est normal : ``` [quote] @@ -27,9 +27,9 @@ Tags can contain line breaks, that's normal: [/quote] ``` -Create a regexp to find all BB-tags with their contents. +Créez une regexp pour trouver tous les BB-tags avec leur contenu. -For instance: +Par exemple : ```js let regexp = /your regexp/flags; @@ -38,7 +38,7 @@ let str = "..[url]http://google.com[/url].."; alert( str.match(regexp) ); // [url]http://google.com[/url] ``` -If tags are nested, then we need the outer tag (if we want we can continue the search in its content): +Si les tags sont imbriqués, alors nous voulons le tag extérieur (si nous voulons nous pouvons continuer la recherche dans le contenu) : ```js let regexp = /your regexp/flags; diff --git a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md index 5a007aee0..f2cf53b65 100644 --- a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md +++ b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/solution.md @@ -1,13 +1,13 @@ -The solution: `pattern:/"(\\.|[^"\\])*"/g`. +La solution : `pattern:/"(\\.|[^"\\])*"/g`. -Step by step: +Etape par etape : -- First we look for an opening quote `pattern:"` -- Then if we have a backslash `pattern:\\` (we technically have to double it in the pattern, because it is a special character, so that's a single backslash in fact), then any character is fine after it (a dot). -- Otherwise we take any character except a quote (that would mean the end of the string) and a backslash (to prevent lonely backslashes, the backslash is only used with some other symbol after it): `pattern:[^"\\]` -- ...And so on till the closing quote. +- D'abord nous recherchons une guillemet ouvrante `pattern:"` +- Ensuite si nous avons un antislash `pattern:\\` (puisque c'est un caractère spécial nous devons le doubler, mais dans les faits c'est un unique antislash), alors n'importe quel caractère peut se trouver à sa suite (un point). +- Sinon nous prenons n'importe quel caractère à part une guillemet (cela signifierait la fin de la chaine de caractère) et un antislash (pour empêcher les antislash solitaires, un antislash est seulement utilisé avec un autre symbole après lui): `pattern:[^"\\]` +- ...Et on continue jusqu'à atteindre la guillemet fermante. -In action: +En action : ```js run let regexp = /"(\\.|[^"\\])*"/g; diff --git a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md index ad41d91b1..95319b51b 100644 --- a/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md +++ b/9-regular-expressions/13-regexp-alternation/03-match-quoted-string/task.md @@ -1,28 +1,28 @@ -# Find quoted strings +# Trouver les chaines de caractère -Create a regexp to find strings in double quotes `subject:"..."`. +Créer une regexp pour trouver les chaines de caractère entre guillemets doubles `subject:"..."`. -The strings should support escaping, the same way as JavaScript strings do. For instance, quotes can be inserted as `subject:\"` a newline as `subject:\n`, and the slash itself as `subject:\\`. +La chaine de caractère devrait supporter l'échappement, comme les chaines de caractère JavaScript. Par exemple, des guillemets peuvent être insérés comme ceci `subject:\"` une nouvelle ligne comme `subject:\n`, et un antislash comme `subject:\\`. ```js let str = "Just like \"here\"."; ``` -Please note, in particular, that an escaped quote `subject:\"` does not end a string. +Veuillez noter qu'une guillemet échapée `subject:\"` ne termine pas une chaine de caractère. -So we should search from one quote to the other ignoring escaped quotes on the way. +Nous devrions donc chercher une guillemet puis la suivante en ignorant celles échapées. -That's the essential part of the task, otherwise it would be trivial. +C'est la partie essentielle de la tâche, à part cela, cela devrait être simple. -Examples of strings to match: +Exemple de chaine de caractère valides : ```js -.. *!*"test me"*/!* .. -.. *!*"Say \"Hello\"!"*/!* ... (escaped quotes inside) -.. *!*"\\"*/!* .. (double slash inside) -.. *!*"\\ \""*/!* .. (double slash and an escaped quote inside) +.. *!*"test me"*/!* .. +.. *!*"Say \"Hello\"!"*/!* ... (guillemets échapées à l'intérieur) +.. *!*"\\"*/!* .. (double slash à l'intérieur) +.. *!*"\\ \""*/!* .. (double slash et guillemets échapées à l'intérieur) ``` -In JavaScript we need to double the slashes to pass them right into the string, like this: +En Javascript nous devons doubler les slash pour les placer dans la chaine de caractère, comme ceci : ```js run let str = ' .. "test me" .. "Say \\"Hello\\"!" .. "\\\\ \\"" .. '; diff --git a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md index 5d4ba8d96..f999566ab 100644 --- a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md +++ b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/solution.md @@ -1,13 +1,13 @@ -The pattern start is obvious: `pattern:`, because `match:` would match it. +...Mais nous ne pouvons pas juste écrire `pattern:` puisque `match:` y correspondrait. -We need either a space after `match:`. +Nous avons besoin soit d'un espace après `match:`. -In the regexp language: `pattern:|\s.*?>)`. +Dans le langage des regexp : `pattern:|\s.*?>)`. -In action: +En action : ```js run let regexp = /|\s.*?>)/g; diff --git a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md index e8a9e31b4..d042949e2 100644 --- a/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md +++ b/9-regular-expressions/13-regexp-alternation/04-match-exact-tag/task.md @@ -1,10 +1,10 @@ -# Find the full tag +# Trouver la balise entière -Write a regexp to find the tag ``. It should match the full tag: it may have no attributes `