Files
.github
api-server
client
config
curriculum
__fixtures__
challenges
_meta
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
basic-javascript-rpg-game
debugging
es6
functional-programming
functional-programming-spreadsheet
intermediate-algorithm-scripting
intermediate-javascript-calorie-counter
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
check-for-all-or-none.md
check-for-mixed-grouping-of-characters.md
extract-matches.md
find-characters-with-lazy-matching.md
find-more-than-the-first-match.md
find-one-or-more-criminals-in-a-hunt.md
ignore-case-while-matching.md
match-a-literal-string-with-different-possibilities.md
match-all-letters-and-numbers.md
match-all-non-numbers.md
match-all-numbers.md
match-anything-with-wildcard-period.md
match-beginning-string-patterns.md
match-characters-that-occur-one-or-more-times.md
match-characters-that-occur-zero-or-more-times.md
match-ending-string-patterns.md
match-everything-but-letters-and-numbers.md
match-letters-of-the-alphabet.md
match-literal-strings.md
match-non-whitespace-characters.md
match-numbers-and-letters-of-the-alphabet.md
match-single-character-with-multiple-possibilities.md
match-single-characters-not-specified.md
match-whitespace.md
positive-and-negative-lookahead.md
remove-whitespace-from-start-and-end.md
restrict-possible-usernames.md
reuse-patterns-using-capture-groups.md
specify-exact-number-of-matches.md
specify-only-the-lower-number-of-matches.md
specify-upper-and-lower-number-of-matches.md
use-capture-groups-to-search-and-replace.md
using-the-test-method.md
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-quality-assurance
07-scientific-computing-with-python
08-data-analysis-with-python
09-information-security
10-coding-interview-prep
11-machine-learning-with-python
12-certificates
schema
test
.babelrc
LICENSE.md
comment-dictionary.js
create-challenge-bundle.js
getChallenges.acceptance.test.js
getChallenges.js
getChallenges.test.js
gulpfile.js
lib.js
package-entry.js
package-lock.json
package.json
utils.js
cypress
docs
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.npmrc
.prettierignore
.prettierrc
.snyk
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
HoF.md
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
crowdin.yml
cypress-install.js
cypress.json
jest.config.js
lerna.json
lighthouserc.js
package-lock.json
package.json
sample.env
2020-09-29 22:09:04 +02:00

78 lines
2.0 KiB
Markdown

---
id: 587d7db3367417b2b2512b8f
title: Match Literal Strings
challengeType: 1
forumTopicId: 301355
---
## 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>:
```js
let testStr = "Hello, my name is Kevin.";
let testRegex = /Kevin/;
testRegex.test(testStr);
// Returns true
```
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>.
```js
let wrongRegex = /kevin/;
wrongRegex.test(testStr);
// Returns false
```
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
tests:
- text: Your regex <code>waldoRegex</code> should find <code>"Waldo"</code>
testString: assert(waldoRegex.test(waldoIsHiding));
- text: Your regex <code>waldoRegex</code> should not search for anything else.
testString: assert(!waldoRegex.test('Somewhere is hiding in this text.'));
- text: You should perform a literal string match with your regex.
testString: assert(!/\/.*\/i/.test(code));
```
</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
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /Waldo/; // Change this line
let result = waldoRegex.test(waldoIsHiding);
```
</section>