Skip to content

Commit f810283

Browse files
Update solution.md
1 parent e43cb3b commit f810283

File tree

1 file changed

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

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
In order to insert after the `<body>` tag, we must first find it. We can use the regular expression pattern `pattern:<body.*?>` for that.
1+
Щоб додати інформацію після тегу `<body>` , нам потрібно спершу його знайти. Ми можемо використати для цього шаблон регулярного виразу `pattern:<body.*?>`.
22

3-
In this task we don't need to modify the `<body>` tag. We only need to add the text after it.
3+
в цьому завданні нам не потрібно змінювати тег `<body>`. Нам потрібно тільки додати текст після нього.
44

5-
Here's how we can do it:
5+
Ось таким чином ми можемо це зробити:
66

77
```js run
88
let str = '...<body style="...">...';
9-
str = str.replace(/<body.*?>/, '$&<h1>Hello</h1>');
9+
str = str.replace(/<body.*?>/, '$&<h1>Привіт</h1>');
1010

11-
alert(str); // ...<body style="..."><h1>Hello</h1>...
11+
alert(str); // ...<body style="..."><h1>Привіт</h1>...
1212
```
1313

14-
In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:<body.*?>`. It gets replaced by itself plus `<h1>Hello</h1>`.
14+
в заміненому рядку `$&` означає співпадіння саме по собі, тобто, частина вихідного тексту яка відповідає шаблону `pattern:<body.*?>`. Її замінено на неї ж плюс `<h1>Привіт</h1>`.
1515

16-
An alternative is to use lookbehind:
16+
Альнернативою було би використання перегляду назад:
1717

1818
```js run
1919
let str = '...<body style="...">...';
20-
str = str.replace(/(?<=<body.*?>)/, `<h1>Hello</h1>`);
20+
str = str.replace(/(?<=<body.*?>)/, `<h1>Привіт</h1>`);
2121

22-
alert(str); // ...<body style="..."><h1>Hello</h1>...
22+
alert(str); // ...<body style="..."><h1>привіт</h1>...
2323
```
2424

25-
As you can see, there's only lookbehind part in this regexp.
25+
Як бачите, є тільки перегляд назад у цьому регулярному виразі.
2626

2727
It works like this:
2828
- At every position in the text.

0 commit comments

Comments
 (0)