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/03-regexp-character-classes/article.md
+44-44Lines changed: 44 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,101 +166,101 @@ let str = "+7(903)-123-45-67";
166
166
alert( str.replace(/\D/g, "") ); // 79031234567
167
167
```
168
168
169
-
## Spaces are regular characters
169
+
## Пробелы – обычные символы
170
170
171
-
Usually we pay little attention to spaces. For us strings`subject:1-5`and `subject:1 - 5`are nearly identical.
171
+
Обычно мы уделяем мало внимания пробелам. Для нас строки`subject:1-5`и`subject:1 - 5`практически идентичны.
172
172
173
-
But if a regexp doesn't take spaces into account, it may fail to work.
173
+
Но если регулярное выражение не учитывает пробелы, оно может не работать.
174
174
175
-
Let's try to find digits separated by a dash:
175
+
Давайте попробуем найти цифры, разделенные тире:
176
176
177
177
```js run
178
-
alert( "1 - 5".match(/\d-\d/) ); // null, no match!
178
+
alert( "1 - 5".match(/\d-\d/) ); // null, нет совпадений!
179
179
```
180
180
181
-
Here we fix it by adding spaces into the regexp`pattern:\d - \d`:
181
+
Здесь мы исправляем это, добавляя пробелы в регулярное выражение`pattern:\d - \d`:
182
182
183
183
```js run
184
-
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, now it works
184
+
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, теперь это работает
185
185
```
186
186
187
-
**A space is a character. Equal in importance with any other character.**
187
+
**Пробел - это символ. По важности он равен любому другому символу.**
188
188
189
-
Of course, spaces in a regexp are needed only if we look for them. Extra spaces (just like any other extra characters) may prevent a match:
189
+
Конечно, пробелы в регулярных выражениях нужны только в том случае, если мы их ищем. Лишние пробелы (как и любые другие лишние символы) могут помешать совпадению:
190
190
191
191
```js run
192
-
alert( "1-5".match(/\d - \d/) ); // null, because the string 1-5 has no spaces
192
+
alert( "1-5".match(/\d - \d/) ); // null, потому что строка '1-5' не содержит пробелов
193
193
```
194
194
195
-
In other words, in a regular expression all characters matter, spaces too.
195
+
Другими словами, в регулярном выражении все символы имеют значение, даже пробелы.
196
196
197
-
## A dot is any character
197
+
## Точка - это любой символ
198
198
199
-
The dot `"."`is a special character class that matches "any character except a newline".
199
+
Точка `"."`- это специальный символьный класс, который соответствует "любому символу, кроме новой строки".
200
200
201
-
For instance:
201
+
Для примера:
202
202
203
203
```js run
204
-
alert( "Z".match(/./) ); //Z
204
+
alert( "Ю".match(/./) ); //Ю
205
205
```
206
206
207
-
Or in the middle of a regexp:
207
+
Или в середине регулярного выражения:
208
208
209
209
```js run
210
210
let reg =/CS.4/;
211
211
212
212
alert( "CSS4".match(reg) ); // CSS4
213
213
alert( "CS-4".match(reg) ); // CS-4
214
-
alert( "CS 4".match(reg) ); // CS 4 (space is also a character)
214
+
alert( "CS 4".match(reg) ); // CS 4 (пробел тоже является символом)
215
215
```
216
216
217
-
Please note that the dot means "any character", but not the "absense of a character". There must be a character to match it:
217
+
Обратите внимание, что точка означает "любой символ", но не "отсутствие символа". Там должен быть каой-либо символ, чтобы соответствовать условию поиска:
218
218
219
219
```js run
220
-
alert( "CS4".match(/CS.4/) ); // null, no match because there's no character for the dot
220
+
alert( "CS4".match(/CS.4/) ); // null, нет совпадений потому что нет символа соответствующего точке
221
221
```
222
222
223
-
### The dotall "s" flag
223
+
### Точка, как буквально любой символ, с флагом "s"
224
224
225
-
Usually a dot doesn't match a newline character.
225
+
Обычно точка не соответствует символу новой строки.
0 commit comments