freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../regular-expressions/match-ending-string-pattern...

2.3 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9e Match Ending String Patterns 1 Шаблоны контуров соответствия

Description

В последней задаче вы научились использовать символ caret для поиска шаблонов в начале строк. Существует также способ поиска шаблонов в конце строк. Вы можете искать конец строк, используя dollar sign $ в конце регулярного выражения.
пусть TheEnding = «Это бесконечная история»;
let storyRegex = / story $ /;
storyRegex.test (theEnding);
// Возвращает true
let noEnding = "Иногда история должна закончиться";
storyRegex.test (noEnding);
// Возвращает false

Instructions

Используйте символ привязки ( $ ), чтобы соответствовать строке "caboose" в конце строки caboose .

Tests

tests:
  - text: ''
    testString: 'assert(lastRegex.source == "caboose$", "You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.");'
  - text: ''
    testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
  - text: Вы должны соответствовать <code>&quot;caboose&quot;</code> в конце строки <code>&quot;The last car on a train is the caboose&quot;</code>
    testString: 'assert(lastRegex.test("The last car on a train is the caboose"), "You should match <code>"caboose"</code> at the end of the string <code>"The last car on a train is the caboose"</code>");'

Challenge Seed

let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);

Solution

// solution required