Skip to content

Commit 08ad9f9

Browse files
authored
Merge pull request #411 from TevaHenry/lookahead-and-lookbehind
Translate lookahead-lookbehind tasks
2 parents 284306e + adad5af commit 08ad9f9

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
The regexp for an integer number is `pattern:\d+`.
2+
L'expression régulière pour un nombre entier est `pattern:\d+`.
33

4-
We can exclude negatives by prepending it with the negative lookbehind: `pattern:(?<!-)\d+`.
4+
Nous pouvons exclure les négatifs en les faisant précéder du lookbehind négatif : `pattern:(?<!-)\d+`.
55

6-
Although, if we try it now, we may notice one more "extra" result:
6+
Bien que, si nous l'essayons maintenant, nous remarquerons peut-être un autre résultat "supplémentaire":
77

88
```js run
99
let regexp = /(?<!-)\d+/g;
@@ -13,11 +13,11 @@ let str = "0 12 -5 123 -18";
1313
console.log( str.match(regexp) ); // 0, 12, 123, *!*8*/!*
1414
```
1515

16-
As you can see, it matches `match:8`, from `subject:-18`. To exclude it, we need to ensure that the regexp starts matching a number not from the middle of another (non-matching) number.
16+
Comme vous pouvez le voir, il correspond à `match:8`, à partir de `subject:-18`. Pour l'exclure, nous devons nous assurer que l'expression régulière commence à correspondre à un nombre qui ne se trouve pas au milieu d'un autre nombre (non correspondant).
1717

18-
We can do it by specifying another negative lookbehind: `pattern:(?<!-)(?<!\d)\d+`. Now `pattern:(?<!\d)` ensures that a match does not start after another digit, just what we need.
18+
Nous pouvons le faire en spécifiant un autre lookbehind négatif : `pattern:(?<!-)(?<!\d)\d+`. Maintenant, `pattern:(?<!\d)` garantit qu'une correspondance ne commence pas après un autre chiffre, juste ce dont nous avons besoin.
1919

20-
We can also join them into a single lookbehind here:
20+
Nous pouvons également les joindre en un seul lookbehind ici:
2121

2222
```js run
2323
let regexp = /(?<![-\d])\d+/g;

9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Find non-negative integers
1+
# Trouver des nombres entiers non négatifs
22

3-
There's a string of integer numbers.
3+
Il y a une chaîne de nombres entiers.
44

5-
Create a regexp that looks for only non-negative ones (zero is allowed).
5+
Créez une expression régulière qui ne recherche que les expressions non négatives (zéro est autorisé).
66

7-
An example of use:
7+
Un exemple d'utilisation :
88
```js
99
let regexp = /your regexp/g;
1010

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
In order to insert after the `<body>` tag, we must first find it. We can use the regular expression pattern `pattern:<body.*?>` for that.
1+
Pour insérer après la balise `<body>`, nous devons d'abord la trouver. Nous pouvons utiliser le modèle d'expression régulière `pattern:<body.*?>` pour cela.
22

3-
In this task we don't need to modify the `<body>` tag. We only need to add the text after it.
3+
Dans cette tâche, nous n'avons pas besoin de modifier la balise `<body>`. Nous n'avons qu'à ajouter le texte après.
44

5-
Here's how we can do it:
5+
Voici comment nous pouvons le faire :
66

77
```js run
88
let str = '...<body style="...">...';
@@ -11,9 +11,9 @@ str = str.replace(/<body.*?>/, '$&<h1>Hello</h1>');
1111
alert(str); // ...<body style="..."><h1>Hello</h1>...
1212
```
1313

14-
In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:<body.*?>`. It gets replaced by itself plus `<h1>Hello</h1>`.
14+
Dans la chaîne de remplacement, `$&` signifie la correspondance elle-même, c'est-à-dire la partie du texte source qui correspond à `pattern:<body.*?>`. Il est remplacé par lui-même suivi de `<h1>Hello</h1>`.
1515

16-
An alternative is to use lookbehind:
16+
Une alternative consiste à utiliser lookbehind :
1717

1818
```js run
1919
let str = '...<body style="...">...';
@@ -22,15 +22,15 @@ str = str.replace(/(?<=<body.*?>)/, `<h1>Hello</h1>`);
2222
alert(str); // ...<body style="..."><h1>Hello</h1>...
2323
```
2424

25-
As you can see, there's only lookbehind part in this regexp.
25+
Comme vous pouvez le voir, il n'y a qu'une partie lookbehind dans cette expression régulière.
2626

27-
It works like this:
28-
- At every position in the text.
29-
- Check if it's preceeded by `pattern:<body.*?>`.
30-
- If it's so then we have the match.
27+
Cela fonctionne comme ceci :
28+
- À chaque position dans le texte.
29+
- Vérifiez s'il est précédé de `pattern:<body.*?>`.
30+
- Si c'est le cas, nous avons le match.
3131

32-
The tag `pattern:<body.*?>` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:<body.*?>`.
32+
La balise `pattern:<body.*?>` 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:<body.*?>`.
3333

34-
So it replaces the "empty line", preceeded by `pattern:<body.*?>`, with `<h1>Hello</h1>`. That's the insertion after `<body>`.
34+
Il remplace donc la "ligne vide", précédée de `pattern:<body.*?>`, par `<h1>Hello</h1>`. C'est l'insertion après `<body>`.
3535

36-
P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also be useful: `pattern:/<body.*?>/si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:<body>` also match `match:<BODY>` case-insensitively.
36+
PS Les drapeaux d'expression régulière, tels que `pattern:s` et `pattern:i` peuvent également être utiles : `pattern:/<body.*?>/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:<body>` correspond également à `match:<BODY>` insensible à la casse.

9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Insert After Head
1+
# Insérer après Body
22

3-
We have a string with an HTML Document.
3+
Nous avons une chaîne avec un document HTML.
44

5-
Write a regular expression that inserts `<h1>Hello</h1>` immediately after `<body>` tag. The tag may have attributes.
5+
Écrivez une expression régulière qui insère `<h1>Hello</h1>` immédiatement après la balise `<body>`. La balise peut avoir des attributs.
66

7-
For instance:
7+
Par exemple:
88

99
```js
1010
let regexp = /your regular expression/;
@@ -20,7 +20,7 @@ let str = `
2020
str = str.replace(regexp, `<h1>Hello</h1>`);
2121
```
2222

23-
After that the value of `str` should be:
23+
Après cela, la valeur de `str` devrait être :
2424
```html
2525
<html>
2626
<body style="height: 200px"><h1>Hello</h1>

0 commit comments

Comments
 (0)