Skip to content

Translated tasks to English Language. #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
In order to insert after the `<body>` tag, you must first find it. We will use the regular expression pattern `pattern:<body.*>`.

Для того, чтобы вставить после тега `<body>`, нужно вначале его найти. Будем использовать регулярное выражение `pattern:<body.*>`.
Next, we need to leave the `<body>` tag in place and add text after it.

Далее, нам нужно оставить сам тег `<body>` на месте и добавить текст после него.

Это можно сделать вот так:
This can be done like this:
```js run
let str = '...<body style="...">...';
str = str.replace(/<body.*>/, '$&<h1>Hello</h1>');

alert(str); // ...<body style="..."><h1>Hello</h1>...
```

В строке замены `$&` означает само совпадение, то есть мы заменяем `pattern:<body.*>` заменяется на самого себя плюс `<h1>Hello</h1>`.
In the replacement string `$&` means the match itself, that is, we replace `pattern:<body.*>` Is replaced by itself plus `<h1>Hello</h1>`.

Альтернативный вариант - использовать ретроспективную проверку:
An alternative is to use retrospective validation:

```js run
let str = '...<body style="...">...';
Expand All @@ -22,8 +21,8 @@ str = str.replace(/(?<=<body.*>)/, `<h1>Hello</h1>`);
alert(str); // ...<body style="..."><h1>Hello</h1>...
```

Такое регулярное выражение на каждой позиции будет проверять, не идёт ли прямо перед ней `pattern:<body.*>`. Если да - совпадение найдено. Но сам тег `pattern:<body.*>` в совпадение не входит, он только участвует в проверке. А других символов после проверки в нём нет, так что текст совпадения будет пустым.
Such a regular expression at each position will check if `pattern:<body.*>`does not go directly in front of it. If yes, a match is found. But the tag `pattern:<body.*>` does not coincide, it only participates in the verification. And there are no other characters after checking in it, so the match text will be empty.

Происходит замена "пустой строки", перед которой идёт `pattern:<body.*>` на `<h1>Hello</h1>`. Что, как раз, и есть вставка этой строки после `<body>`.
This replaces the "empty line", followed by `pattern:<body.*>` With `<h1>Hello</h1>`. Which, exactly, is the insertion of this line after `<body>`.

P.S. Этому регулярному выражению не помешают флаги: `pattern:/<body.*>/si`, чтобы в "точку" входил перевод строки (тег может занимать несколько строк), а также чтобы теги в другом регистре типа `match:<BODY>` тоже находились.
P.S. The flags: `pattern:/<body.*>/si`, will not interfere with this regular expression, so that a line break appears in the "dot" (a tag can span several lines), and also that the tags are in a different register of the `match:<BODY>` type, too.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Вставьте после фрагмента
# Insert After Head

Есть строка с HTML-документом.
There is a line with an HTML Document.

Вставьте после тега `<body>` (у него могут быть атрибуты) строку `<h1>Hello</h1>`.
Insert after tag `<body>` (it may have attributes) line `<h1>Hello</h1>`.

Например:
For instance:

```js
let regexp = /ваше регулярное выражение/;
let regexp = /your regular expression/;

let str = `
<html>
Expand All @@ -20,7 +20,7 @@ let str = `
str = str.replace(regexp, `<h1>Hello</h1>`);
```

После этого значение `str`:
After that value `str`:
```html
<html>
<body style="height: 200px"><h1>Hello</h1>
Expand Down