File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6 Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 1- A regexp to search 3-digit color ` #abc ` : ` pattern:/#[a-f0-9]{3}/i ` .
1+ Une regexp pour chercher une couleur à trois chiffres ` #abc ` : ` pattern:/#[a-f0-9]{3}/i ` .
22
3- We can add exactly 3 more optional hex digits. We don't need more or less. The color has either 3 or 6 digits .
3+ Nous pouvons y ajouter les 3 autres chiffres optionnels. Nous n'avons pas besoin de plus ou moins. La couleur a soit 3 ou 6 chiffres .
44
5- Let's use the quantifier ` pattern:{1,2} ` for that: we'll have ` pattern:/#([a-f0-9]{3}){1,2}/i ` .
5+ Utilisons le quantificateur ` pattern:{1,2} ` pour obtenir ` pattern:/#([a-f0-9]{3}){1,2}/i ` .
66
7- Here the pattern ` pattern:[a-f0-9]{3} ` is enclosed in parentheses to apply the quantifier ` pattern:{1,2} ` .
7+ Ici le schéma ` pattern:[a-f0-9]{3} ` est entouré de parenthèses pour lui appliquer le quantificateur ` pattern:{1,2} ` .
88
9- In action :
9+ En pratique :
1010
1111``` js run
1212let regexp = / #([a-f0-9 ] {3} ){1,2} / gi ;
@@ -16,7 +16,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1616alert ( str .match (regexp) ); // #3f3 #AA00ef #abc
1717```
1818
19- There's a minor problem here: the pattern found ` match:#abc ` in ` subject:#abcd ` . To prevent that we can add ` pattern:\b ` to the end :
19+ Il reste un petit problème ici : car ce schéma trouve ` match:#abc ` dans ` subject:#abcd ` . Pour éviter cela nous pouvons y ajouter ` pattern:\b ` à la fin :
2020
2121``` js run
2222let regexp = / #([a-f0-9 ] {3} ){1,2} \b / gi ;
Original file line number Diff line number Diff line change 1- # Find color in the format #abc or #abcdef
1+ # Trouver des couleurs au format #abc ou #abcdef
22
3- Write a RegExp that matches colors in the format ` #abc ` or ` #abcdef ` . That is : ` # ` followed by 3 or 6 hexadecimal digits .
3+ Écrire une RegExp qui correspond à des couleurs au format ` #abc ` ou ` #abcdef ` . C'est à dire : ` # ` suivi par 3 ou 6 chiffres hexadécimaux .
44
5- Usage example :
5+ Exemple d'utilisation :
66``` js
77let regexp = / your regexp/ g ;
88
@@ -11,4 +11,4 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
1111alert ( str .match (regexp) ); // #3f3 #AA00ef
1212```
1313
14- P.S. This should be exactly 3 or 6 hex digits. Values with 4 digits, such as ` #abcd ` , should not match .
14+ P.S. Cela doit être exactement 3 ou 6 chiffres. Des valeurs avec 4 chiffres, comme ` #abcd ` , ne doivent pas ressortir .
You can’t perform that action at this time.
0 commit comments