2018-09-30 23:01:58 +01:00
---
id: 587d7db3367417b2b2512b8f
title: Match Literal Strings
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301355
2021-01-13 03:31:00 +01:00
dashedName: match-literal-strings
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2021-03-02 16:12:12 -08:00
In the last challenge, you searched for the word `Hello` using the regular expression `/Hello/` . That regex searched for a literal match of the string `Hello` . Here's another example searching for a literal match of the string `Kevin` :
2019-05-17 06:20:30 -07:00
```js
let testStr = "Hello, my name is Kevin.";
let testRegex = /Kevin/;
testRegex.test(testStr);
```
2021-03-02 16:12:12 -08:00
This `test` call will return `true` .
Any other forms of `Kevin` will not match. For example, the regex `/Kevin/` will not match `kevin` or `KEVIN` .
2019-05-17 06:20:30 -07:00
```js
let wrongRegex = /kevin/;
wrongRegex.test(testStr);
```
2021-03-02 16:12:12 -08:00
This `test` call will return `false` .
2018-09-30 23:01:58 +01:00
A future challenge will show how to match those other forms as well.
2020-11-27 19:02:05 +01:00
# --instructions--
Complete the regex `waldoRegex` to find `"Waldo"` in the string `waldoIsHiding` with a literal match.
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
2021-03-02 16:12:12 -08:00
Your regex `waldoRegex` should find the string `Waldo`
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
2021-10-06 09:14:50 +02:00
waldoRegex.lastIndex = 0;
2020-11-27 19:02:05 +01:00
assert(waldoRegex.test(waldoIsHiding));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex `waldoRegex` should not search for anything else.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
2021-10-06 09:14:50 +02:00
waldoRegex.lastIndex = 0;
2020-11-27 19:02:05 +01:00
assert(!waldoRegex.test('Somewhere is hiding in this text.'));
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should perform a literal string match with your regex.
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(!/\/.*\/i/.test(code));
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 waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /search/; // Change this line
let result = waldoRegex.test(waldoIsHiding);
```
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 waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /Waldo/; // Change this line
let result = waldoRegex.test(waldoIsHiding);
2018-09-30 23:01:58 +01:00
```