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 b5ea34c

Browse files
authored
Merge pull request #1707 from imabp/master
Translated tasks to English Language.
2 parents 1e475bf + 1a22912 commit b5ea34c

File tree

2 files changed

+14
-15
lines changed
  • 9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head

2 files changed

+14
-15
lines changed
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1+
In order to insert after the `<body>` tag, you must first find it. We will use the regular expression pattern `pattern:<body.*>`.
12

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

4-
Далее, нам нужно оставить сам тег `<body>` на месте и добавить текст после него.
5-
6-
Это можно сделать вот так:
5+
This can be done like this:
76
```js run
87
let str = '...<body style="...">...';
98
str = str.replace(/<body.*>/, '$&<h1>Hello</h1>');
109

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

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

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

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

25-
Такое регулярное выражение на каждой позиции будет проверять, не идёт ли прямо перед ней `pattern:<body.*>`. Если да - совпадение найдено. Но сам тег `pattern:<body.*>` в совпадение не входит, он только участвует в проверке. А других символов после проверки в нём нет, так что текст совпадения будет пустым.
24+
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.
2625

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

29-
P.S. Этому регулярному выражению не помешают флаги: `pattern:/<body.*>/si`, чтобы в "точку" входил перевод строки (тег может занимать несколько строк), а также чтобы теги в другом регистре типа `match:<BODY>` тоже находились.
28+
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.

‎9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Вставьте после фрагмента
1+
# Insert After Head
22

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

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

7-
Например:
7+
For instance:
88

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

1212
let str = `
1313
<html>
@@ -20,7 +20,7 @@ let str = `
2020
str = str.replace(regexp, `<h1>Hello</h1>`);
2121
```
2222

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

0 commit comments

Comments
(0)

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