From 9926fc4f0b6945271465427e243a41314cc85c4b Mon Sep 17 00:00:00 2001 From: git-antonyuk Date: Sun, 24 Jul 2022 23:07:04 +0200 Subject: [PATCH 1/3] translation: Anchors: string start ^ and end $ --- .../04-regexp-anchors/1-start-end/solution.md | 6 +-- .../04-regexp-anchors/1-start-end/task.md | 4 +- .../04-regexp-anchors/article.md | 42 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/9-regular-expressions/04-regexp-anchors/1-start-end/solution.md b/9-regular-expressions/04-regexp-anchors/1-start-end/solution.md index 702f992d7..dcf38afb3 100644 --- a/9-regular-expressions/04-regexp-anchors/1-start-end/solution.md +++ b/9-regular-expressions/04-regexp-anchors/1-start-end/solution.md @@ -1,5 +1,5 @@ -An empty string is the only match: it starts and immediately finishes. +Порожній рядок є єдиним збігом: він починається і негайно закінчується. -The task once again demonstrates that anchors are not characters, but tests. +Задача ще раз доводить що якорі не являються символами, вони є тестами. -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. +Рядок порожній `""`. Механізм спочатку відповідає `pattern:^` (початок введення), так, він там, а потім одразу кінцевий `pattern:$`, він також є тут. Отже, збіг є. diff --git a/9-regular-expressions/04-regexp-anchors/1-start-end/task.md b/9-regular-expressions/04-regexp-anchors/1-start-end/task.md index abdfec938..94ce8102d 100644 --- a/9-regular-expressions/04-regexp-anchors/1-start-end/task.md +++ b/9-regular-expressions/04-regexp-anchors/1-start-end/task.md @@ -1,3 +1,3 @@ -# Regexp ^$ +# Регулярний вираз ^$ -Which string matches the pattern `pattern:^$`? +Який рядок буде відповідати шаблону `pattern:^$`? diff --git a/9-regular-expressions/04-regexp-anchors/article.md b/9-regular-expressions/04-regexp-anchors/article.md index 63e4efa93..529d57fe6 100644 --- a/9-regular-expressions/04-regexp-anchors/article.md +++ b/9-regular-expressions/04-regexp-anchors/article.md @@ -1,34 +1,34 @@ -# Anchors: string start ^ and end $ +# Якорі: початок рядка ^ і кінець $ -The caret `pattern:^` and dollar `pattern:$` characters have special meaning in a regexp. They are called "anchors". +Символи каретки `pattern:^` і долара `pattern:$` мають особливе значення в регулярному виразі. Їх називають "якорі". -The caret `pattern:^` matches at the beginning of the text, and the dollar `pattern:$` -- at the end. +Каретка `pattern:^` збігається з початком тексту, а долар `pattern:$` з кінцем. -For instance, let's test if the text starts with `Mary`: +Наприклад, перевіримо, чи текст починається з `Марійка`: ```js run -let str1 = "Mary had a little lamb"; -alert( /^Mary/.test(str1) ); // true +let str1 = "Марійка мала маленьке ягня"; +alert( /^Марійка/.test(str1) ); // true ``` -The pattern `pattern:^Mary` means: "string start and then Mary". +Шаблон `pattern:^Марійка` означає: "початок рядка, а потім Марійка". -Similar to this, we can test if the string ends with `snow` using `pattern:snow$`: +Відповідно, ми можемо протестувати чи закінчується рядок з `сніг` використавши `pattern:сніг$` ```js run -let str1 = "its fleece was white as snow"; -alert( /snow$/.test(str1) ); // true +let str1 = "ця шерсть була білою як сніг"; +alert( /сніг$/.test(str1) ); // true ``` -In these particular cases we could use string methods `startsWith/endsWith` instead. Regular expressions should be used for more complex tests. +Конкретно в цих випадках ми можемо використати методи рядка `startsWith/endsWith`. Для складніших тестів слід використовувати регулярні вирази. -## Testing for a full match +## Перевірка на повний збіг -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. +Обидва якорі разом `pattern:^...$` часто використовуються для перевірки того, чи рядок повністю відповідає шаблону. Наприклад, щоб перевірити, чи введені користувачем дані мають правильний формат. -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. +Перевіримо, чи є рядок часом у форматі: `12:34`. Тобто: дві цифри, потім двокрапка, а потім ще дві цифри. -In regular expressions language that's `pattern:\d\d:\d\d`: +У мові регулярних виразів це так `pattern:\d\d:\d\d`: ```js run let goodInput = "12:34"; @@ -39,14 +39,14 @@ alert( regexp.test(goodInput) ); // true alert( regexp.test(badInput) ); // false ``` -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. +Тут збіг для `pattern:\d\d:\d\d` має починатися точно після початку тексту `pattern:^`, а кінцевий `pattern:$` має йти відразу в слід. -The whole string must be exactly in this format. If there's any deviation or an extra character, the result is `false`. +Весь рядок має бути саме в цьому форматі. Якщо є будь-яке відхилення або додатковий символ, результатом буде `false`. -Anchors behave differently if flag `pattern:m` is present. We'll see that in the next article. +Якір поводиться інакше, якщо присутній прапорець `pattern:m`. Розглянемо це в наступній статті. -```smart header="Anchors have \"zero width\"" -Anchors `pattern:^` and `pattern:$` are tests. They have zero width. +```smart header="У якорів \"нульова ширина\"" +Якорі `pattern:^` та `pattern:$` - це перевірки. В них нульова ширина. -In other words, they do not match a character, but rather force the regexp engine to check the condition (text start/end). +Іншими словами, вони не додають до результату пошуку символи, а лише заставляють рушій регулярних виразів перевірити умову (початок/кінець тексту). ``` From 838319c6ca21c151c42dd9359bfa92eb4026dcea Mon Sep 17 00:00:00 2001 From: Stanislav Date: Wed, 12 Oct 2022 12:34:17 +0300 Subject: [PATCH 2/3] Update 9-regular-expressions/04-regexp-anchors/article.md --- 9-regular-expressions/04-regexp-anchors/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/04-regexp-anchors/article.md b/9-regular-expressions/04-regexp-anchors/article.md index 529d57fe6..71064066c 100644 --- a/9-regular-expressions/04-regexp-anchors/article.md +++ b/9-regular-expressions/04-regexp-anchors/article.md @@ -28,7 +28,7 @@ alert( /сніг$/.test(str1) ); // true Перевіримо, чи є рядок часом у форматі: `12:34`. Тобто: дві цифри, потім двокрапка, а потім ще дві цифри. -У мові регулярних виразів це так `pattern:\d\d:\d\d`: +У мові регулярних виразів це виглядає так `pattern:\d\d:\d\d`: ```js run let goodInput = "12:34"; From c13615c75010dd4e11d63ebbc37f5596b12967cd Mon Sep 17 00:00:00 2001 From: Stanislav Date: Wed, 12 Oct 2022 12:34:27 +0300 Subject: [PATCH 3/3] Update 9-regular-expressions/04-regexp-anchors/article.md --- 9-regular-expressions/04-regexp-anchors/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/9-regular-expressions/04-regexp-anchors/article.md b/9-regular-expressions/04-regexp-anchors/article.md index 71064066c..cf6445146 100644 --- a/9-regular-expressions/04-regexp-anchors/article.md +++ b/9-regular-expressions/04-regexp-anchors/article.md @@ -46,7 +46,7 @@ alert( regexp.test(badInput) ); // false Якір поводиться інакше, якщо присутній прапорець `pattern:m`. Розглянемо це в наступній статті. ```smart header="У якорів \"нульова ширина\"" -Якорі `pattern:^` та `pattern:$` - це перевірки. В них нульова ширина. +Якорі `pattern:^` та `pattern:$` -- це перевірки. В них нульова ширина. Іншими словами, вони не додають до результату пошуку символи, а лише заставляють рушій регулярних виразів перевірити умову (початок/кінець тексту). ``` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy