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
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
In the last challenge, you searched for the word < code > "Hello"< / code > using the regular expression < code > /Hello/< / code > . That regex searched for a literal match of the string < code > "Hello"< / code > . Here's another example searching for a literal match of the string < code > "Kevin"< / code > :
2019-05-17 06:20:30 -07:00
```js
let testStr = "Hello, my name is Kevin.";
let testRegex = /Kevin/;
testRegex.test(testStr);
// Returns true
```
2018-09-30 23:01:58 +01:00
Any other forms of < code > "Kevin"< / code > will not match. For example, the regex < code > /Kevin/< / code > will not match < code > "kevin"< / code > or < code > "KEVIN"< / code > .
2019-05-17 06:20:30 -07:00
```js
let wrongRegex = /kevin/;
wrongRegex.test(testStr);
// Returns false
```
2018-09-30 23:01:58 +01:00
A future challenge will show how to match those other forms as well.
< / section >
## Instructions
< section id = 'instructions' >
Complete the regex < code > waldoRegex< / code > to find < code > "Waldo"< / code > in the string < code > waldoIsHiding< / code > with a literal match.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: Your regex < code > waldoRegex</ code > should find < code > "Waldo"</ code >
2019-07-24 02:32:04 -07:00
testString: assert(waldoRegex.test(waldoIsHiding));
2018-10-04 14:37:37 +01:00
- text: Your regex < code > waldoRegex</ code > should not search for anything else.
2019-07-24 02:32:04 -07:00
testString: assert(!waldoRegex.test('Somewhere is hiding in this text.'));
2018-10-04 14:37:37 +01:00
- text: You should perform a literal string match with your regex.
2019-07-24 02:32:04 -07:00
testString: assert(!/\/.*\/i/.test(code));
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /search/; // Change this line
let result = waldoRegex.test(waldoIsHiding);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```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
```
2019-07-18 08:24:12 -07:00
2018-09-30 23:01:58 +01:00
< / section >