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..cf6445146 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). +Іншими словами, вони не додають до результату пошуку символи, а лише заставляють рушій регулярних виразів перевірити умову (початок/кінець тексту). ```
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: