2018-10-10 18:03:03 -04:00
---
id: 587d7db7367417b2b2512b9e
title: Match Ending String Patterns
challengeType: 1
2019-08-28 16:26:13 +03:00
forumTopicId: 301352
2018-10-10 18:03:03 -04:00
localeTitle: Шаблоны контуров соответствия
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
В последней задаче вы научились использовать символ < code > caret< / code > для поиска шаблонов в начале строк. Существует также способ поиска шаблонов в конце строк. Вы можете искать конец строк, используя < code > dollar sign< / code > < code > $< / code > в конце регулярного выражения. < blockquote > пусть TheEnding = «Это бесконечная история»; < br > let storyRegex = / story $ /; < br > storyRegex.test (theEnding); < br > // Возвращает true < br > let noEnding = " Иногда история должна закончиться" ; < br > storyRegex.test (noEnding); < br > // Возвращает false < br > < / blockquote >
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
Используйте символ привязки ( < code > $< / code > ), чтобы соответствовать строке < code > " caboose" < / code > в конце строки < code > caboose< / code > .
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: You should search for < code > "caboose"</ code > with the dollar sign < code > $</ code > anchor in your regex.
testString: assert(lastRegex.source == "caboose$");
- text: Your regex should not use any flags.
testString: assert(lastRegex.flags == "");
- text: You should match < code > "caboose"</ code > at the end of the string < code > "The last car on a train is the caboose"</ code >
testString: assert(lastRegex.test("The last car on a train is the caboose"));
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >