forked from javascript-tutorial/en.javascript.info
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
133 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
...ressions-javascript/10-regexp-backreferences/1-find-matching-bbtags/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
Открывающий тег -- это <code class="pattern">\[(b|url|quote)\]</code>. | ||
|
||
Для того, чтобы найти всё до закрывающего -- используем ленивый поиск <code class="pattern">[\s\S]*?</code> и обратную ссылку на открывающий тег. | ||
|
||
Итого, получится: <code class="pattern">\[(b|url|quote)\][\s\S]*?\[/\1\]</code>. | ||
|
||
В действии: | ||
|
||
```js | ||
//+ run | ||
var re = /\[(b|url|quote)\][\s\S]*?\[\/\1\]/g; | ||
|
||
var str1 = "..[url]http://ya.ru[/url].."; | ||
var str2 = "..[url][b]http://ya.ru[/b][/url].."; | ||
|
||
alert( str1.match(re) ); // [url]http://ya.ru[/url] | ||
alert( str2.match(re) ); // [url][b]http://ya.ru[/b][/url] | ||
``` | ||
|
||
Для закрывающего тега `[/1]` понадобилось дополнительно экранировать слеш: `\[\/1\]`. |
41 changes: 41 additions & 0 deletions
41
...-expressions-javascript/10-regexp-backreferences/1-find-matching-bbtags/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Найдите пары тегов | ||
|
||
ББ-тег имеет вид `[имя]...[/имя]`, где имя -- слово, одно из: `b`, `url`, `quote`. | ||
|
||
Например: | ||
``` | ||
[b]текст[/b] | ||
[url]http://ya.ru[/url] | ||
``` | ||
|
||
ББ-теги могут быть вложенными, но сам в себя тег быть вложен не может, например: | ||
|
||
``` | ||
Допустимо: | ||
[url] [b]http://ya.ru[/b] [/url] | ||
[quote] [b]текст[/b] [/quote] | ||
Нельзя: | ||
[b][b]текст[/b][/b] | ||
``` | ||
|
||
Создайте регулярное выражение для поиска ББ-тегов и их содержимого. | ||
|
||
Например: | ||
|
||
```js | ||
var re = /* регулярка */ | ||
|
||
var str = "..[url]http://ya.ru[/url].."; | ||
alert( str.match(re) ); // [url]http://ya.ru[/url] | ||
``` | ||
|
||
Если теги вложены, то нужно искать самый внешний тег (при желании можно будет продолжить поиск в его содержимом): | ||
|
||
```js | ||
var re = /* регулярка */ | ||
|
||
var str = "..[url][b]http://ya.ru[/b][/url].."; | ||
alert( str.match(re) ); // [url][b]http://ya.ru[/b][/url] | ||
``` | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
21 changes: 21 additions & 0 deletions
21
...gular-expressions-javascript/9-regexp-groups/1-find-webcolor-3-or-6/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Регулярное выражение для поиска 3-значного цвета: <code class="pattern">/#[a-f0-9]{3}/i</code>. | ||
|
||
Нужно добавить ещё три символа, причём нужны именно три, четыре или семь символов не нужны. Эти три символа либо есть, либо нет. | ||
|
||
Самый простой способ добавить -- просто дописать в конец регэкспа: <code class="pattern">/#[a-f0-9]{3}([a-f0-9]{3})?/i</code> | ||
|
||
Можно поступить и хитрее: <code class="pattern">/#([a-f0-9]{3}){1,2}/i</code>. | ||
|
||
Здесь регэксп <code class="pattern">[a-f0-9]{3}</code> заключён в скобки, чтобы квантификатор <code class="pattern">{1,2}</code> применялся целиком ко всей этой структуре. | ||
|
||
В действии: | ||
```js | ||
//+ run | ||
var re = /#([a-f0-9]{3}){1,2}/gi; | ||
|
||
var str = "color: #3f3; background-color: #AA00ef; and: #abcd"; | ||
|
||
alert( str.match(re) ); // #3f3 #AA0ef #abc | ||
``` | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
11-regular-expressions-javascript/9-regexp-groups/1-find-webcolor-3-or-6/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Найдите цвет в формате #abc или #abcdef | ||
|
||
Напишите регулярное выражение, которое находит цвет в формате `#abc` или `#abcdef`. То есть, символ `#`, после которого идут 3 или 6 шестнадцатиричных символа. | ||
|
||
Пример использования: | ||
```js | ||
var re = /* ваш регэксп */ | ||
|
||
var str = "color: #3f3; background-color: #AA00ef; and: #abcd"; | ||
|
||
alert( str.match(re) ); // #3f3 #AA0ef | ||
``` | ||
|
||
P.S. Значения из четырёх и более букв, такие как `#abcd` мы в этой задаче также учитываем, но берём из них только необходимые для совпадения символы, то есть `#abc`. |
53 changes: 53 additions & 0 deletions
53
11-regular-expressions-javascript/9-regexp-groups/2-parse-expression/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Регулярное выражение для числа, возможно, дробного и отрицательного: <code class="pattern">-?\d+(\.\d+)?</code>. Мы уже разбирали его в предыдущих задачах. | ||
|
||
Оператор -- это <code class="pattern">[-+*/]</code>. Заметим, что дефис <code class="pattern">-</code> идёт в списке первым, так как на любой позиции, кроме первой и последней, он имеет специальный смысл внутри <code class="pattern">[...]</code>, и его понадобилось бы экранировать. | ||
|
||
Кроме того, когда мы оформим это в JavaScript-синтаксис <code class="pattern">/.../</code> -- понадобится заэкранировать слэш <code class="pattern">/</code>. | ||
|
||
Нам нужно число, затем оператор, затем число, и необязательные пробелы между ними. | ||
|
||
Полное регулярное выражение будет таким: <code class="pattern">-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?</code>. | ||
|
||
Чтобы получить результат в виде массива, добавим скобки вокруг тех данных, которые нам интересны, то есть -- вокруг чисел и оператора: <code class="pattern">(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)</code>. | ||
|
||
Посмотрим в действии: | ||
```js | ||
//+ run | ||
var re = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/; | ||
|
||
alert( "1.2 + 12".match(re) ); | ||
``` | ||
|
||
Итоговый массив будет включать в себя компоненты: | ||
|
||
<ul> | ||
<li>`result[0] == "1.2 + 12"` (вначале всегда полное совпадение)</li> | ||
<li>`result[1] == "1"` (первая скобка)</li> | ||
<li>`result[2] == "2"` (вторая скобка -- дробная часть `(\.\d+)?`)</li> | ||
<li>`result[3] == "+"` (...)</li> | ||
<li>`result[4] == "12"` (...)</li> | ||
<li>`result[5] == undefined` (последняя скобка, но у второго числа дробная часть отсутствует)</li> | ||
</ul> | ||
|
||
Нам из этого массива нужны только числа и оператор. А, скажем, дробная часть сама по себе -- не нужна. | ||
|
||
Уберём её из запоминания, добавив в начало скобки <code class="pattern">?:</code>, то есть: <code class="pattern">(?:\.\d+)?</code>. | ||
|
||
Итого, решение: | ||
|
||
```js | ||
//+ run | ||
function parse(expr) { | ||
var re = /(-?\d+(?:\.\d+)?)\s*([-+*\/])\s*(-?\d+(?:\.\d+)?)/; | ||
|
||
var result = expr.match(re); | ||
|
||
if (!result) return; | ||
result.shift(); | ||
|
||
return result; | ||
} | ||
|
||
alert( parse("-1.23 * 3.45") ); // -1.23, *, 3.45 | ||
``` | ||
|
20 changes: 20 additions & 0 deletions
20
11-regular-expressions-javascript/9-regexp-groups/2-parse-expression/task.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Разобрать выражение | ||
|
||
Арифметическое выражение состоит из двух чисел и операции между ними, например: | ||
<ul> | ||
<li>`1 + 2`</li> | ||
<li>`1.2 * 3.4`</li> | ||
<li>`-3 / -6`</li> | ||
<li>-2 - 2`</li> | ||
</ul> | ||
|
||
Список операций: `"+"`, `"-"`, `"*"` и `"/"`. | ||
|
||
Также могут присутсововать пробелы вокруг оператора и чисел. | ||
|
||
Напишите функцию, которая будет получать выражение и возвращать массив из трёх аргументов: | ||
<ol> | ||
<li>Первое число.</li> | ||
<li>Оператор.</li> | ||
<li>Второе число.</li> | ||
</ul> |
File renamed without changes.
File renamed without changes
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ouseover-mouseout-mouseenter-mouseleave/mouseenter-mouseleave-delegation-2.view/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#text { | ||
display: block; | ||
height: 100px; | ||
width: 400px; | ||
width: 456px; | ||
} | ||
|
||
#table th { | ||
|
2 changes: 1 addition & 1 deletion
2
...-mouseover-mouseout-mouseenter-mouseleave/mouseenter-mouseleave-delegation.view/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#text { | ||
display: block; | ||
height: 100px; | ||
width: 400px; | ||
width: 456px; | ||
} | ||
|
||
#table th { | ||
|
2 changes: 1 addition & 1 deletion
2
...ails/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/mouseleave-table.view/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#text { | ||
display: block; | ||
height: 100px; | ||
width: 400px; | ||
width: 456px; | ||
} | ||
|
||
#table th { | ||
|
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.