Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
check-for-all-or-none.english.md
check-for-mixed-grouping-of-characters.english.md
extract-matches.english.md
find-characters-with-lazy-matching.english.md
find-more-than-the-first-match.english.md
find-one-or-more-criminals-in-a-hunt.english.md
ignore-case-while-matching.english.md
match-a-literal-string-with-different-possibilities.english.md
match-all-letters-and-numbers.english.md
match-all-non-numbers.english.md
match-all-numbers.english.md
match-anything-with-wildcard-period.english.md
match-beginning-string-patterns.english.md
match-characters-that-occur-one-or-more-times.english.md
match-characters-that-occur-zero-or-more-times.english.md
match-ending-string-patterns.english.md
match-everything-but-letters-and-numbers.english.md
match-letters-of-the-alphabet.english.md
match-literal-strings.english.md
match-non-whitespace-characters.english.md
match-numbers-and-letters-of-the-alphabet.english.md
match-single-character-with-multiple-possibilities.english.md
match-single-characters-not-specified.english.md
match-whitespace.english.md
positive-and-negative-lookahead.english.md
remove-whitespace-from-start-and-end.english.md
restrict-possible-usernames.english.md
reuse-patterns-using-capture-groups.english.md
specify-exact-number-of-matches.english.md
specify-only-the-lower-number-of-matches.english.md
specify-upper-and-lower-number-of-matches.english.md
use-capture-groups-to-search-and-replace.english.md
using-the-test-method.english.md
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
portuguese
russian
spanish
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
guide
mock-guide
search-indexing
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.french.md
README.italian.md
README.korean.md
README.md
SECURITY.md
azure-pipelines.yml
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
libcimp_index_js.patch
package-lock.json
package.json
patch_npm_and_install.sh
sample.env
freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/check-for-mixed-grouping-of-characters.english.md

74 lines
2.8 KiB
Markdown
Raw Normal View History

---
id: 5c3dda8b4d8df89bea71600f
title: Check For Mixed Grouping of Characters
challengeType: 1
---
## Description
<section id='description'>
Sometimes we want to check for groups of characters using a Regular Expression and to achieve that we use parentheses <code>()</code>.
If you want to find either <code>Penguin</code> or <code>Pumpkin</code> in a string, you can use the following Regular Expression: <code>/P(engu|umpk)in/g</code>
Then check whether the desired string groups are in the test string by using the <code>test()</code> method.
```js
let testStr = "Pumpkin";
let testRegex = /P(engu|umpk)in/g;
testRegex.test(testStr);
// Returns true
```
</section>
## Instructions
<section id='instructions'>
Fix the regex so that it checks for the names of <code>Franklin Roosevelt</code> or <code>Eleanor Roosevelt</code> in a case sensitive manner and it should make concessions for middle names.
Then fix the code so that the regex that you have created is checked against <code>myString</code> and either <code>true</code> or <code>false</code> is returned depending on whether the regex matches.
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Franklin D. Roosevelt</code>
testString: assert(myRegex.test('Franklin D. Roosevelt'), 'Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Franklin D. Roosevelt</code>');
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Eleanor Roosevelt</code>
testString: assert(myRegex.test('Eleanor Roosevelt'), 'Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Eleanor Roosevelt</code>');
- text: Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Franklin Rosevelt</code>
testString: assert(!myRegex.test('Franklin Rosevelt'), 'Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Franklin Rosevelt</code>');
- text: You should use <code>.test()</code> to test the regex.
testString: assert(code.match(/myRegex.test\(\s*myString\s*\)/), 'You should use <code>.test()</code> to test the regex.');
- text: Your result should return <code>true</code>.
testString: assert(result === true, 'Your result should return <code>true</code>.');
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
let myString = "Eleanor Roosevelt";
let myRegex = /False/; // Change this line
let result = false; // Change this line
// After passing the challenge experiment with myString and see how the grouping works
```
</div>
</section>
## Solution
<section id='solution'>
```js
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);
```
</section>