2021-06-15 00:49:18 -07:00
---
id: 587d7db7367417b2b2512b9e
2021-07-21 20:53:20 +05:30
title: Encontrar padrões ao final da string
2021-06-15 00:49:18 -07:00
challengeType: 1
forumTopicId: 301352
dashedName: match-ending-string-patterns
---
# --description--
2021-07-16 11:03:16 +05:30
No desafio anterior, você aprendeu a usar o circunflexo para capturar padrões no início de strings. Há também uma maneira de buscar padrões no fim de strings.
2021-06-15 00:49:18 -07:00
2021-07-16 11:03:16 +05:30
Se você colocar um cifrão, `$` , no fim da regex, você pode buscar no fim de strings.
2021-06-15 00:49:18 -07:00
```js
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
```
2021-07-16 11:03:16 +05:30
A primeira chamada a `test` retorna `true` enquanto a segunda retorna `false` .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-16 11:03:16 +05:30
Use o cifrão (`$` ) para capturar a string `caboose` no fim da string `caboose` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-16 11:03:16 +05:30
Você deve usar o cifrão `$` na sua regex para buscar a string `caboose` .
2021-06-15 00:49:18 -07:00
```js
assert(lastRegex.source == 'caboose$');
```
2021-07-30 23:57:21 +09:00
A regex não deve usar nenhuma flag.
2021-06-15 00:49:18 -07:00
```js
assert(lastRegex.flags == '');
```
2021-07-16 11:03:16 +05:30
Você deve capturar `caboose` no fim da string `The last car on a train is the caboose`
2021-06-15 00:49:18 -07:00
```js
2021-10-06 08:36:48 -07:00
lastRegex.lastIndex = 0;
2021-06-15 00:49:18 -07:00
assert(lastRegex.test('The last car on a train is the caboose'));
```
# --seed--
## --seed-contents--
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
```
# --solutions--
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);
```