Skip to content

Commit d56cf3a

Browse files
authored
Merge pull request #287 from XyoloJR/regex10
Greedy and lazy quantifiers
2 parents 8bf7243 + f0a8e25 commit d56cf3a

File tree

7 files changed

+123
-123
lines changed

7 files changed

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

2-
The result is: `match:123 4`.
2+
La réponse est : `match:123 4`.
33

4-
First the lazy `pattern:\d+?` tries to take as little digits as it can, but it has to reach the space, so it takes `match:123`.
4+
Pour commencer, le motif paresseux `pattern:\d+?` essaye de prendre aussi peu de chiffres que possible, mais il doit atteindre ensuite un espace, donc il prend `match:123`.
55

6-
Then the second `\d+?` takes only one digit, because that's enough.
6+
Ensuite le second `\d+?` prend seulement un chiffre, parce que ça suffit.

9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A match for /d+? d+?/
1+
# Correspondance pour /d+? d+?/
22

3-
What's the match here?
3+
Quel est la correspondance trouvée ici ?
44

55
```js
66
alert( "123 456".match(/\d+? \d+?/g) ); // ?

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
1+
Nous devons trouver le début d'un commentaire `match:<!--`, puis tout jusqu'à la fin de `match:-->`.
22

3-
An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`. We also need to add flag `pattern:s` for the dot to include newlines.
3+
Une expression régulière possible est `pattern:<!--.*?-->` -- le quantificateur paresseux arrête le point juste avant `match:-->`. Nous avons aussi besoin du marqueur `pattern:s` pour que le point inclue les nouvelles lignes.
44

5-
Otherwise multiline comments won't be found:
5+
Les commentaires multi-lignes ne seraient pas trouvés sans ce marqueur :
66

77
```js run
88
let regexp = /<!--.*?-->/gs;

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Find HTML comments
1+
# Trouvez des commentaires HTML
22

3-
Find all HTML comments in the text:
3+
Trouvez tous les commentaires HTML dans le texte :
44

55
```js
66
let regexp = /your regexp/g;

9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
The solution is `pattern:<[^<>]+>`.
2+
Une solution `pattern:<[^<>]+>`.
33

44
```js run
55
let regexp = /<[^<>]+>/g;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Find HTML tags
1+
# Trouver des balises HTML
22

3-
Create a regular expression to find all (opening and closing) HTML tags with their attributes.
3+
Écrire une expression régulière pour trouver toutes les balises HTML (ouvrantes et fermantes) avec leurs attributs.
44

5-
An example of use:
5+
Exemple d'usage :
66

77
```js run
88
let regexp = /your regexp/g;
@@ -12,4 +12,4 @@ let str = '<> <a href="/"> <input type="radio" checked> <b>';
1212
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
1313
```
1414

15-
Here we assume that tag attributes may not contain `<` and `>` (inside quotes too), that simplifies things a bit.
15+
Pour simplifier un peu, nous considérons ici qu'une balise ne peut pas contenir de `<` ou `>` (même à l'intérieur de guillemets).

9-regular-expressions/10-regexp-greedy-and-lazy/article.md

Lines changed: 108 additions & 108 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)