2018-09-30 23:01:58 +01:00
---
id: 587d7db7367417b2b2512b9e
title: Match Ending String Patterns
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301352
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2019-10-27 15:45:37 -01: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-11-27 19:02:05 +01:00
You can search the end of strings using the dollar sign character `$` at the end of the regex.
2019-05-17 06:20:30 -07: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-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Use the anchor character (`$` ) to match the string `"caboose"` at the end of the string `caboose` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should search for `"caboose"` with the dollar sign `$` anchor in your regex.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(lastRegex.source == 'caboose$');
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex should not use any flags.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(lastRegex.flags == '');
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should match `"caboose"` at the end of the string `"The last car on a train is the caboose"`
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(lastRegex.test('The last car on a train is the caboose'));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
2019-05-03 03:05:26 -07:00
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);
2018-09-30 23:01:58 +01:00
```