You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 9-regular-expressions/10-regexp-greedy-and-lazy/article.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,20 @@
1
1
# Greedy and lazy quantifiers
2
2
3
-
Quantifiers are very simple from the first sight, but in fact they can be tricky.
3
+
Les quantificateurs sont, à première vue, très simples, mais peuvent parfois être retors.
4
4
5
-
We should understand how the search works very well if we plan to look for something more complex than`pattern:/\d+/`.
5
+
Nous devons mieux comprendre comment marche une recherche pour arriver à trouver des modèles plus complexes que`pattern:/\d+/`.
6
6
7
-
Let's take the following task as an example.
7
+
Prenons comme exemple la tâche suivante.
8
8
9
-
We have a text and need to replace all quotes `"..."`with guillemet marks: `«...»`. They are preferred for typography in many countries.
9
+
Nous avons un texte dans lequel nous devons remplacer tous les guillemets droits (doubles) `"..."`par des guillemets français : `«...»`, qui sont préférés en typographie dans de nombreux pays.
10
10
11
-
For instance: `"Hello, world"`should become `«Hello, world»`. There exist other quotes, such as `„Witam, świat!”` (Polish) or`「你好,世界」` (Chinese), but for our task let's choose`«...»`.
11
+
Par exemple : `"Hello, world"`devrait se transformer en `«Hello, world»`. Il existe d'autre guillemets, comme `„Witam, świat!”` (polonais) ou`「你好,世界」` (chinois), mais pour notre exemple choisissons`«...»`.
12
12
13
-
The first thing to do is to locate quoted strings, and then we can replace them.
13
+
La première chose à faire est de trouver ces guillemets droits, et nous pourrons alors les remplacer.
14
14
15
-
A regular expression like `pattern:/".+"/g` (a quote, then something, then the other quote) may seem like a good fit, but it isn't!
15
+
Une expression régulière comme `pattern:/".+"/g` (des guillemets, puis quelque chose, puis d'autres guillemets) semble être une bonne approche, mais pas exactement !
16
16
17
-
Let's try it:
17
+
Essayons ça:
18
18
19
19
```js run
20
20
let regexp =/".+"/g;
@@ -24,11 +24,11 @@ let str = 'a "witch" and her "broom" is one';
24
24
alert( str.match(regexp) ); // "witch" and her "broom"
25
25
```
26
26
27
-
...We can see that it works not as intended!
27
+
... Nous pouvons voir que ça ne marche exactement comme prévu !
28
28
29
-
Instead of finding two matches `match:"witch"`and`match:"broom"`, it finds one: `match:"witch" and her "broom"`.
29
+
Au lieu de trouver deux correspondances `match:"witch"`et`match:"broom"`, il n'en trouve qu'une : `match:"witch" and her "broom"`.
30
30
31
-
That can be described as "greediness is the cause of all evil".
31
+
Qui peut être vu comme "l'avidité est la cause de tout mal".
0 commit comments