Skip to content

Commit 33e5561

Browse files
authored
Merge pull request #376 from git-antonyuk/translation/regexp-anchors
Anchors: string start ^ and end $
2 parents 0db6d5f + c13615c commit 33e5561

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
An empty string is the only match: it starts and immediately finishes.
1+
Порожній рядок є єдиним збігом: він починається і негайно закінчується.
22

3-
The task once again demonstrates that anchors are not characters, but tests.
3+
Задача ще раз доводить що якорі не являються символами, вони є тестами.
44

5-
The string is empty `""`. The engine first matches the `pattern:^` (input start), yes it's there, and then immediately the end `pattern:$`, it's here too. So there's a match.
5+
Рядок порожній `""`. Механізм спочатку відповідає `pattern:^` (початок введення), так, він там, а потім одразу кінцевий `pattern:$`, він також є тут. Отже, збіг є.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Regexp ^$
1+
# Регулярний вираз ^$
22

3-
Which string matches the pattern `pattern:^$`?
3+
Який рядок буде відповідати шаблону `pattern:^$`?
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
# Anchors: string start ^ and end $
1+
# Якорі: початок рядка ^ і кінець $
22

3-
The caret `pattern:^` and dollar `pattern:$` characters have special meaning in a regexp. They are called "anchors".
3+
Символи каретки `pattern:^` і долара `pattern:$` мають особливе значення в регулярному виразі. Їх називають "якорі".
44

5-
The caret `pattern:^` matches at the beginning of the text, and the dollar `pattern:$` -- at the end.
5+
Каретка `pattern:^` збігається з початком тексту, а долар `pattern:$` з кінцем.
66

7-
For instance, let's test if the text starts with `Mary`:
7+
Наприклад, перевіримо, чи текст починається з `Марійка`:
88

99
```js run
10-
let str1 = "Mary had a little lamb";
11-
alert( /^Mary/.test(str1) ); // true
10+
let str1 = "Марійка мала маленьке ягня";
11+
alert( /^Марійка/.test(str1) ); // true
1212
```
1313

14-
The pattern `pattern:^Mary` means: "string start and then Mary".
14+
Шаблон `pattern:^Марійка` означає: "початок рядка, а потім Марійка".
1515

16-
Similar to this, we can test if the string ends with `snow` using `pattern:snow$`:
16+
Відповідно, ми можемо протестувати чи закінчується рядок з `сніг` використавши `pattern:сніг$`
1717

1818
```js run
19-
let str1 = "its fleece was white as snow";
20-
alert( /snow$/.test(str1) ); // true
19+
let str1 = "ця шерсть була білою як сніг";
20+
alert( /сніг$/.test(str1) ); // true
2121
```
2222

23-
In these particular cases we could use string methods `startsWith/endsWith` instead. Regular expressions should be used for more complex tests.
23+
Конкретно в цих випадках ми можемо використати методи рядка `startsWith/endsWith`. Для складніших тестів слід використовувати регулярні вирази.
2424

25-
## Testing for a full match
25+
## Перевірка на повний збіг
2626

27-
Both anchors together `pattern:^...$` are often used to test whether or not a string fully matches the pattern. For instance, to check if the user input is in the right format.
27+
Обидва якорі разом `pattern:^...$` часто використовуються для перевірки того, чи рядок повністю відповідає шаблону. Наприклад, щоб перевірити, чи введені користувачем дані мають правильний формат.
2828

29-
Let's check whether or not a string is a time in `12:34` format. That is: two digits, then a colon, and then another two digits.
29+
Перевіримо, чи є рядок часом у форматі: `12:34`. Тобто: дві цифри, потім двокрапка, а потім ще дві цифри.
3030

31-
In regular expressions language that's `pattern:\d\d:\d\d`:
31+
У мові регулярних виразів це виглядає так `pattern:\d\d:\d\d`:
3232

3333
```js run
3434
let goodInput = "12:34";
@@ -39,14 +39,14 @@ alert( regexp.test(goodInput) ); // true
3939
alert( regexp.test(badInput) ); // false
4040
```
4141

42-
Here the match for `pattern:\d\d:\d\d` must start exactly after the beginning of the text `pattern:^`, and the end `pattern:$` must immediately follow.
42+
Тут збіг для `pattern:\d\d:\d\d` має починатися точно після початку тексту `pattern:^`, а кінцевий `pattern:$` має йти відразу в слід.
4343

44-
The whole string must be exactly in this format. If there's any deviation or an extra character, the result is `false`.
44+
Весь рядок має бути саме в цьому форматі. Якщо є будь-яке відхилення або додатковий символ, результатом буде `false`.
4545

46-
Anchors behave differently if flag `pattern:m` is present. We'll see that in the next article.
46+
Якір поводиться інакше, якщо присутній прапорець `pattern:m`. Розглянемо це в наступній статті.
4747

48-
```smart header="Anchors have \"zero width\""
49-
Anchors `pattern:^` and `pattern:$` are tests. They have zero width.
48+
```smart header="У якорів \"нульова ширина\""
49+
Якорі `pattern:^` та `pattern:$` -- це перевірки. В них нульова ширина.
5050
51-
In other words, they do not match a character, but rather force the regexp engine to check the condition (text start/end).
51+
Іншими словами, вони не додають до результату пошуку символи, а лише заставляють рушій регулярних виразів перевірити умову (початок/кінець тексту).
5252
```

0 commit comments

Comments
 (0)