You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An empty string is the only match: it starts and immediately finishes.
1
+
Порожній рядок є єдиним збігом: він починається і негайно закінчується.
2
2
3
-
The task once again demonstrates that anchors are not characters, but tests.
3
+
Задача ще раз доводить що якорі не являються символами, вони є тестами.
4
4
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:$`, він також є тут. Отже, збіг є.
The caret`pattern:^`and dollar`pattern:$`characters have special meaning in a regexp. They are called "anchors".
3
+
Символи каретки`pattern:^`і долара`pattern:$`мають особливе значення в регулярному виразі. Їх називають "якорі".
4
4
5
-
The caret `pattern:^`matches at the beginning of the text, and the dollar `pattern:$`-- at the end.
5
+
Каретка `pattern:^`збігається з початком тексту, а долар `pattern:$`з кінцем.
6
6
7
-
For instance, let's test if the text starts with `Mary`:
7
+
Наприклад, перевіримо, чи текст починається з `Марійка`:
8
8
9
9
```js run
10
-
let str1 ="Mary had a little lamb";
11
-
alert(/^Mary/.test(str1) ); // true
10
+
let str1 ="Марійка мала маленьке ягня";
11
+
alert(/^Марійка/.test(str1) ); // true
12
12
```
13
13
14
-
The pattern `pattern:^Mary` means: "string start and then Mary".
14
+
Шаблон `pattern:^Марійка` означає: "початок рядка, а потім Марійка".
15
15
16
-
Similar to this, we can test if the string ends with `snow` using`pattern:snow$`:
16
+
Відповідно, ми можемо протестувати чи закінчується рядок з `сніг` використавши`pattern:сніг$`
17
17
18
18
```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
21
21
```
22
22
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`. Для складніших тестів слід використовувати регулярні вирази.
24
24
25
-
## Testing for a full match
25
+
## Перевірка на повний збіг
26
26
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:^...$`часто використовуються для перевірки того, чи рядок повністю відповідає шаблону. Наприклад, щоб перевірити, чи введені користувачем дані мають правильний формат.
28
28
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`. Тобто: дві цифри, потім двокрапка, а потім ще дві цифри.
30
30
31
-
In regular expressions language that's`pattern:\d\d:\d\d`:
31
+
У мові регулярних виразів це виглядає так`pattern:\d\d:\d\d`:
0 commit comments