Skip to content

Commit 20a3b98

Browse files
committed
translate escaping in set part
1 parent faf145a commit 20a3b98

File tree

1 file changed

+17
-17
lines changed
  • 9-regular-expressions/08-regexp-character-sets-and-ranges

1 file changed

+17
-17
lines changed

9-regular-expressions/08-regexp-character-sets-and-ranges/article.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ Les propriétés Unicode `pattern:p{…}` ne sont pas implémentées dans IE. Si
9393
Ou simplement utiliser des intervalles de caractères dans la langue qui nous intéresse, e.g. `pattern:[а-я]` pour les lettres cyrilliques.
9494
```
9595

96-
## Intervalles excluant
96+
## Intervalles d'exclusion
9797

98-
En plus de ces intervalles classiques, existent les intervalles "excluant" qui ressemblent à `pattern:[^…]`.
98+
En plus des intervalles classiques, existent les intervalles d'exclusion qui ressemblent à `pattern:[^…]`.
9999

100100
Ils se distinguent par un premier accent circonflexe `^` et correspond à n'importe quel caractère *à l'exception des caractères qui le suivent*.
101101

@@ -111,37 +111,37 @@ L'exemple ci-dessous cherche n'importe quel caractère n'étant pas une lettre,
111111
alert( "alice15@gmail.com".match(/[^\d\sA-Z]/gi) ); // @ et .
112112
```
113113

114-
## Escaping in []
114+
## L'échappement entre []
115115

116-
Usually when we want to find exactly a special character, we need to escape it like `pattern:\.`. And if we need a backslash, then we use `pattern:\\`, and so on.
116+
Habituellement, lorsque nous cherchons précisément un caractère spécial, nous devons l'échapper `pattern:\.`. Et si nous cherchons un backslash, nous utilisons `pattern:\\`, et ainsi de suite.
117117

118-
In square brackets we can use the vast majority of special characters without escaping:
118+
À l'intérieur de crochets nous pouvons utiliser une grande majorité des caractères spéciaux sans échappement :
119119

120-
- Symbols `pattern:. + ( )` never need escaping.
121-
- A hyphen `pattern:-` is not escaped in the beginning or the end (where it does not define a range).
122-
- A caret `pattern:^` is only escaped in the beginning (where it means exclusion).
123-
- The closing square bracket `pattern:]` is always escaped (if we need to look for that symbol).
120+
- Les symbols `pattern:. + ( )` ne sont jamais échappés.
121+
- Un tiret `pattern:-` n'est pas échappé en début ou fin d'ensemble (là où il ne peut pas définir d'intervalle).
122+
- Un accent circonflexe `pattern:^` est échappé uniquement s'il débute l'ensemble (sinon il signifie l'exclusion).
123+
- Le crochet fermant `pattern:]` est toujours échappé (si nous le cherchons précisément).
124124

125-
In other words, all special characters are allowed without escaping, except when they mean something for square brackets.
125+
En d'autres termes, tous les caractères spéciaux ne sont pas échappés, sauf s'ils ont un sens particulier pour un ensemble.
126126

127-
A dot `.` inside square brackets means just a dot. The pattern `pattern:[.,]` would look for one of characters: either a dot or a comma.
127+
Un point `.` à l'intérieur de crochets signifie juste un point. Le modèle `pattern:[.,]` recherche un caractère : soit un point soit une virgule.
128128

129-
In the example below the regexp `pattern:[-().^+]` looks for one of the characters `-().^+`:
129+
Dans l'exemple ci-dessous l'expression rationnelle `pattern:[-().^+]` cherche un des caractères `-().^+`:
130130

131131
```js run
132-
// No need to escape
132+
// Pas besoin d'échapper
133133
let regexp = /[-().^+]/g;
134134

135-
alert( "1 + 2 - 3".match(regexp) ); // Matches +, -
135+
alert( "1 + 2 - 3".match(regexp) ); // trouve +, -
136136
```
137137

138-
...But if you decide to escape them "just in case", then there would be no harm:
138+
... Si vous décidez par contre de les échapper "au cas où", il n'y aura pas d'impact :
139139

140140
```js run
141-
// Escaped everything
141+
// Tout échappé
142142
let regexp = /[\-\(\)\.\^\+]/g;
143143

144-
alert( "1 + 2 - 3".match(regexp) ); // also works: +, -
144+
alert( "1 + 2 - 3".match(regexp) ); // fonctionne aussi: +, -
145145
```
146146

147147
## Ranges and flag "u"

0 commit comments

Comments
 (0)