Skip to content

Commit 92cce27

Browse files
authored
Merge pull request #163 from ca11ado/regexp-greedy-and-lazy
9-regular-expressions/08-regexp-greedy-and-lazy/article.md
2 parents 8816aa6 + 022ea1b commit 92cce27

7 files changed

Lines changed: 129 additions & 128 deletions

File tree

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

2-
The result is: `match:123 4`.
2+
Результат будет: `match:123 4`.
33

4-
First the lazy `pattern:\d+?` tries to take as little digits as it can, but it has to reach the space, so it takes `match:123`.
4+
Первый, ленивый шаблон, `pattern:\d+?` попытается получить как можно меньше цифр до первого пробела, поэтому совпадением будет `match:123`.
55

6-
Then the second `\d+?` takes only one digit, because that's enough.
6+
Тогда второй `\d+?` возьмёт только одну цифру, потому что этого будет достаточно.

9-regular-expressions/08-regexp-greedy-and-lazy/1-lazy-greedy/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A match for /d+? d+?/
1+
# Совпадение для /d+? d+?/
22

3-
What's the match here?
3+
Какое здесь будет совпадение?
44

55
```js
66
"123 456".match(/\d+? \d+?/g) ); // ?

9-regular-expressions/08-regexp-greedy-and-lazy/3-find-html-comments/solution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
1+
Нам нужно найти начало комментария `match:<!--`. После этого, весь текст до конца комментария `match:-->`.
22

3-
The first idea could be `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`.
3+
Первой идеей может быть `pattern:<!--.*?-->` -- ленивый квантификатор остановит точку прямо перед `match:-->`.
44

5-
But a dot in JavaScript means "any symbol except the newline". So multiline comments won't be found.
5+
Но точка в JavaScript означает "любой символ, кроме новой строки". Так что многострочные комментарии не будут найдены.
66

7-
We can use `pattern:[\s\S]` instead of the dot to match "anything":
7+
Мы можем использовать `pattern:[\s\S]` вместо точки, чтобы найти "всё":
88

99
```js run
1010
let reg = /<!--[\s\S]*?-->/g;

9-regular-expressions/08-regexp-greedy-and-lazy/3-find-html-comments/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Find HTML comments
1+
# Поиск HTML-комментариев
22

3-
Find all HTML comments in the text:
3+
Найти все HTML-комментарии в тексте:
44

55
```js
6-
let reg = /your regexp/g;
6+
let reg = /ваше регулярное выражение/g;
77

88
let str = `... <!-- My -- comment
99
test --> .. <!----> ..

9-regular-expressions/08-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
The solution is `pattern:<[^<>]+>`.
2+
Решением будет `pattern:<[^<>]+>`.
33

44
```js run
55
let reg = /<[^<>]+>/g;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Find HTML tags
1+
# Поиск HTML-тегов
22

3-
Create a regular expression to find all (opening and closing) HTML tags with their attributes.
3+
Создайте регулярное выражение, чтобы найти все (открывающие и закрывающие) HTML-теги с их атрибутами.
44

5-
An example of use:
5+
Пример использования:
66

77
```js run
8-
let reg = /your regexp/g;
8+
let reg = /ваше регулярное выражение/g;
99

1010
let str = '<> <a href="/"> <input type="radio" checked> <b>';
1111

1212
alert( str.match(reg) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
1313
```
1414

15-
Let's assume that may not contain `<` and `>` inside (in quotes too), that simplifies things a bit.
15+
В этой задаче мы предполагаем, что атрибуты тегов не содержат `<` и `>` (и в кавычках тоже), это немного упрощает её решение.

0 commit comments

Comments
 (0)