From 46ecc87dd0ed0280a403c9377283fa1c953327cb Mon Sep 17 00:00:00 2001 From: Teva Henry Date: Mon, 10 Oct 2022 22:56:44 +1300 Subject: [PATCH 1/2] Translate lookahead-lookbehind tasks --- .../1-find-non-negative-integers/solution.md | 12 ++++----- .../1-find-non-negative-integers/task.md | 11 ++++---- .../2-insert-after-head/solution.md | 26 +++++++++---------- .../2-insert-after-head/task.md | 10 +++---- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md index ebc12689d..fb0af09c8 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md @@ -1,9 +1,9 @@ -The regexp for an integer number is `pattern:\d+`. +L'expression régulière pour un nombre entier est `pattern:\d+`. -We can exclude negatives by prepending it with the negative lookbehind: `pattern:(?` tag, we must first find it. We can use the regular expression pattern `pattern:` for that. +Pour insérer après la balise ``, nous devons d'abord la trouver. Nous pouvons utiliser le modèle d'expression régulière `pattern:` pour cela. -In this task we don't need to modify the `` tag. We only need to add the text after it. +Dans cette tâche, nous n'avons pas besoin de modifier la balise ``. Nous n'avons qu'à ajouter le texte après. -Here's how we can do it: +Voici comment nous pouvons le faire : ```js run let str = '......'; @@ -11,9 +11,9 @@ str = str.replace(//, '$&

Hello

'); alert(str); // ...

Hello

... ``` -In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:`. It gets replaced by itself plus `

Hello

`. +Dans la chaîne de remplacement, `$&` signifie la correspondance elle-même, c'est-à-dire la partie du texte source qui correspond à `pattern:`. Il est remplacé par lui-même suivi de `

Hello

`. -An alternative is to use lookbehind: +Une alternative consiste à utiliser lookbehind : ```js run let str = '......'; @@ -22,15 +22,15 @@ str = str.replace(/(?<=)/, `

Hello

`); alert(str); // ...

Hello

... ``` -As you can see, there's only lookbehind part in this regexp. +Comme vous pouvez le voir, il n'y a qu'une partie lookbehind dans cette expression régulière. -It works like this: -- At every position in the text. -- Check if it's preceeded by `pattern:`. -- If it's so then we have the match. +Cela fonctionne comme ceci : +- À chaque position dans le texte. +- Vérifiez s'il est précédé de `pattern:`. +- Si c'est le cas, nous avons le match. -The tag `pattern:` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:`. +La balise `pattern:` ne sera pas renvoyée. Le résultat de cette expression régulière est littéralement une chaîne vide, mais elle ne correspond qu'aux positions précédées de `pattern:`. -So it replaces the "empty line", preceeded by `pattern:`, with `

Hello

`. That's the insertion after ``. +Il remplace donc la "ligne vide", précédée de `pattern:`, par `

Hello

`. C'est l'insertion après ``. -P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also be useful: `pattern://si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:` also match `match:` case-insensitively. +PS Les drapeaux d'expression régulière, tels que `pattern:s` et `pattern:i` peuvent également être utiles : `pattern://si`. Le drapeau `pattern:s` fait correspondre le point `pattern:.` à un caractère de retour à la ligne, et le drapeau `pattern:i` fait que `pattern:` correspond également à `match:` insensible à la casse. diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md index be1a259f6..c54624a04 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md @@ -1,10 +1,10 @@ -# Insert After Head +# Insérer après Body -We have a string with an HTML Document. +Nous avons une chaîne avec un document HTML. -Write a regular expression that inserts `

Hello

` immediately after `` tag. The tag may have attributes. +Écrivez une expression régulière qui insère `

Hello

` immédiatement après la balise ``. La balise peut avoir des attributs. -For instance: +Par exemple: ```js let regexp = /your regular expression/; @@ -20,7 +20,7 @@ let str = ` str = str.replace(regexp, `

Hello

`); ``` -After that the value of `str` should be: +Après cela, la valeur de `str` devrait être : ```html

Hello

From adad5af928e51fbce7505368bde61f4b8646969a Mon Sep 17 00:00:00 2001 From: Teva Henry Date: Mon, 10 Oct 2022 22:59:34 +1300 Subject: [PATCH 2/2] fix format --- .../1-find-non-negative-integers/task.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md index 0a64b3507..47eee023d 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md @@ -5,11 +5,10 @@ Il y a une chaîne de nombres entiers. Créez une expression régulière qui ne recherche que les expressions non négatives (zéro est autorisé). Un exemple d'utilisation : - ```js let regexp = /your regexp/g; let str = "0 12 -5 123 -18"; -alert(str.match(regexp)); // 0, 12, 123 +alert( str.match(regexp) ); // 0, 12, 123 ``` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy