Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc0b185

Browse files
committed
WIP
1 parent f21cb0a commit fc0b185

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
Ответ: `pattern:\b\d\d:\d\d\b`.
2+
The answer: `pattern:\b\d\d:\d\d\b`.
33

44
```js run
5-
alert( "Завтрак в 09:00 в комнате 123:456.".match( /\b\d\d:\d\d\b/ ) ); // 09:00
5+
alert( "Breakfast at 09:00 in the room 123:456.".match( /\b\d\d:\d\d\b/ ) ); // 09:00
66
```
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Найдите время
1+
# Find the time
22

3-
Время имеет формат: `часы:минуты`. И часы, и минуты имеют две цифры, например, `09:00`.
3+
The time has a format: `hours:minutes`. Both hours and minutes has two digits, like `09:00`.
44

5-
Введите регулярное выражение, чтобы найти время в строке: `subject:Завтрак в 09:00 в комнате 123:456.`
5+
Make a regexp to find time in the string: `subject:Breakfast at 09:00 in the room 123:456.`
66

7-
P.S. В этой задаче пока нет необходимости проверять правильность времени, поэтому `25:99` также может быть верным результатом.
7+
P.S. In this task there's no need to check time correctness yet, so `25:99` can also be a valid result.
88

9-
P.P.S. Регулярное выражение не должно находить `123:456`.
9+
P.P.S. The regexp shouldn't match `123:456`.

‎9-regular-expressions/06-regexp-boundary/article.md‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,28 @@ So, it matches the pattern `pattern:\bHello\b`, because:
2525

2626
1. At the beginning of the string matches the first test `pattern:\b`.
2727
2. Then matches the word `pattern:Hello`.
28-
3. Then the test `pattern:\b` - matches again, as we're between `subject:o` and a space.
28+
3. Then the test `pattern:\b` matches again, as we're between `subject:o` and a space.
2929

30-
Шаблон `pattern:\bJava\b` также совпадёт. Но не `pattern:\bHell\b` (потому что после `subject:l` нет границы слова), и не `pattern:Java!\b` (восклицательный знак не является "символом слова" `pattern:\w`, поэтому после него нет границы слова).
30+
The pattern `pattern:\bJava\b` would also match. But not `pattern:\bHell\b` (because there's no word boundary after `l`) and not `Java!\b` (because the exclamation sign is not a wordly character `pattern:\w`, so there's no word boundary after it).
3131

3232
```js run
3333
alert( "Hello, Java!".match(/\bHello\b/) ); // Hello
3434
alert( "Hello, Java!".match(/\bJava\b/) ); // Java
35-
alert( "Hello, Java!".match(/\bHell\b/) ); // null (нет совпадения)
36-
alert( "Hello, Java!".match(/\bJava!\b/) ); // null (нет совпадения)
35+
alert( "Hello, Java!".match(/\bHell\b/) ); // null (no match)
36+
alert( "Hello, Java!".match(/\bJava!\b/) ); // null (no match)
3737
```
3838

39-
Так как `pattern:\b` является проверкой, то не добавляет символ после границы к результату.
39+
We can use `pattern:\b` not only with words, but with digits as well.
4040

41-
Мы можем использовать `pattern:\b` не только со словами, но и с цифрами.
42-
43-
Например, регулярное выражение `pattern:\b\d\d\b` ищет отдельно стоящие двузначные числа. Другими словами, оно требует, чтобы до и после `pattern:\d\d` был символ, отличный от `pattern:\w` (или начало/конец строки)
41+
For example, the pattern `pattern:\b\d\d\b` looks for standalone 2-digit numbers. In other words, it looks for 2-digit numbers that are surrounded by characters different from `pattern:\w`, such as spaces or punctuation (or text start/end).
4442

4543
```js run
4644
alert( "1 23 456 78".match(/\b\d\d\b/g) ); // 23,78
45+
alert( "12,34,56".match(/\b\d\d\b/g) ); // 12,34,56
4746
```
4847

49-
```warn header="Граница слова `pattern:\b` не работает для алфавитов, не основанных на латинице"
50-
Проверка границы слова `pattern:\b` проверяет границу, должно быть `pattern:\w` с одной стороны и "не `pattern:\w`" - с другой.
48+
```warn header="Word boundary `pattern:\b` doesn't work for non-latin alphabets"
49+
The word boundary test `pattern:\b` checks that there should be `pattern:\w` on the one side from the position and "not `pattern:\w`" - on the other side.
5150

52-
Но `pattern:\w` означает латинскую букву (или цифру или знак подчёркивания), поэтому проверка не будет работать для других символов (например, кириллицы или иероглифов).
51+
But `pattern:\w` means a latin letter `a-z` (or a digit or an underscore), so the test doesn't work for other characters, e.g. cyrillic letters or hieroglyphs.
5352
```

‎9-regular-expressions/07-regexp-escaping/article.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
# Escaping, special characters
33

4-
As we've seen, a backslash `"\"` is used to denote character classes. So it's a special character in regexps (just like in a regular string).
4+
As we've seen, a backslash `pattern:\` is used to denote character classes, e.g. `pattern:\d`. So it's a special character in regexps (just like in regular strings).
55

66
There are other special characters as well, that have special meaning in a regexp. They are used to do more powerful searches. Here's a full list of them: `pattern:[ \ ^ $ . | ? * + ( )`.
77

88
Don't try to remember the list -- soon we'll deal with each of them separately and you'll know them by heart automatically.
99

1010
## Escaping
1111

12-
Let's say we want to find a dot literally. Not "any character", but just a dot.
12+
Let's say we want to find literally a dot. Not "any character", but just a dot.
1313

1414
To use a special character as a regular one, prepend it with a backslash: `pattern:\.`.
1515

@@ -43,11 +43,11 @@ Here's what a search for a slash `'/'` looks like:
4343
alert( "/".match(/\//) ); // '/'
4444
```
4545

46-
On the other hand, if we're not using `/.../`, but create a regexp using `new RegExp`, then we don't need to escape it:
46+
On the other hand, if we're not using `pattern:/.../`, but create a regexp using `new RegExp`, then we don't need to escape it:
4747

4848
```js run
49-
alert( "/".match(new RegExp("/")) ); // '/'
50-
```
49+
alert( "/".match(new RegExp("/")) ); // finds /
50+
```
5151

5252
## new RegExp
5353

@@ -61,25 +61,25 @@ let reg = new RegExp("\d\.\d");
6161
alert( "Chapter 5.1".match(reg) ); // null
6262
```
6363

64-
The search worked with `pattern:/\d\.\d/`, but with `new RegExp("\d\.\d")` it doesn't work, why?
64+
The similar search in one of previous examples worked with `pattern:/\d\.\d/`, but `new RegExp("\d\.\d")` doesn't work, why?
6565

66-
The reason is that backslashes are "consumed" by a string. Remember, regular strings have their own special characters like `\n`, and a backslash is used for escaping.
66+
The reason is that backslashes are "consumed" by a string. As we may recall, regular strings have their own special characters, such as `\n`, and a backslash is used for escaping.
6767

68-
Please, take a look, what "\d\.\d" really is:
68+
Here's how "\d\.\d" is preceived:
6969

7070
```js run
7171
alert("\d\.\d"); // d.d
7272
```
7373

74-
The quotes "consume" backslashes and interpret them, for instance:
74+
String quotes "consume" backslashes and interpret them on their own, for instance:
7575

7676
- `\n` -- becomes a newline character,
7777
- `\u1234` -- becomes the Unicode character with such code,
7878
- ...And when there's no special meaning: like `pattern:\d` or `\z`, then the backslash is simply removed.
7979

80-
So the call to `new RegExp` gets a string without backslashes. That's why the search doesn't work!
80+
So `new RegExp` gets a string without backslashes. That's why the search doesn't work!
8181

82-
To fix it, we need to double backslashes, because quotes turn `\\` into `\`:
82+
To fix it, we need to double backslashes, because string quotes turn `\\` into `\`:
8383

8484
```js run
8585
*!*
@@ -94,6 +94,6 @@ alert( "Chapter 5.1".match(reg) ); // 5.1
9494

9595
## Summary
9696

97-
- To search special characters `pattern:[ \ ^ $ . | ? * + ( )` literally, we need to prepend them with `\` ("escape them").
97+
- To search for special characters `pattern:[ \ ^ $ . | ? * + ( )` literally, we need to prepend them with a backslash `\` ("escape them").
9898
- We also need to escape `/` if we're inside `pattern:/.../` (but not inside `new RegExp`).
99-
- When passing a string `new RegExp`, we need to double backslashes `\\`, cause strings consume one of them.
99+
- When passing a string `new RegExp`, we need to double backslashes `\\`, cause string quotes consume one of them.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /