2018-10-10 18:03:03 -04:00
---
id: 587d7db7367417b2b2512b9e
2021-02-06 04:42:36 +00:00
title: Match Ending String Patterns
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301352
2021-01-13 03:31:00 +01:00
dashedName: match-ending-string-patterns
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
In the last challenge, you learned to use the caret character to search for patterns at the beginning of strings. There is also a way to search for patterns at the end of strings.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
You can search the end of strings using the dollar sign character `$` at the end of the regex.
2020-08-04 15:14:01 +08:00
```js
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
// Returns false
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Use the anchor character (`$` ) to match the string `"caboose"` at the end of the string `caboose` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should search for `"caboose"` with the dollar sign `$` anchor in your regex.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(lastRegex.source == 'caboose$');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex should not use any flags.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(lastRegex.flags == '');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
You should match `"caboose"` at the end of the string `"The last car on a train is the caboose"`
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(lastRegex.test('The last car on a train is the caboose'));
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-01-13 03:31:00 +01:00
# --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);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);
```