2020-08-04 15:14:01 +08:00
---
id: 5c3dda8b4d8df89bea71600f
2021-02-06 04:42:36 +00:00
title: Check For Mixed Grouping of Characters
2020-08-04 15:14:01 +08:00
challengeType: 1
forumTopicId: 301339
2021-01-13 03:31:00 +01:00
dashedName: check-for-mixed-grouping-of-characters
2020-08-04 15:14:01 +08:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
Sometimes we want to check for groups of characters using a Regular Expression and to achieve that we use parentheses `()` .
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
If you want to find either `Penguin` or `Pumpkin` in a string, you can use the following Regular Expression: `/P(engu|umpk)in/g`
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
Then check whether the desired string groups are in the test string by using the `test()` method.
2020-08-04 15:14:01 +08:00
```js
let testStr = "Pumpkin";
2021-02-06 04:42:36 +00:00
let testRegex = /P(engu|umpk)in/;
2020-08-04 15:14:01 +08:00
testRegex.test(testStr);
// Returns true
```
2020-12-16 00:37:30 -07:00
# --instructions--
2021-02-06 04:42:36 +00:00
Fix the regex so that it checks for the names of `Franklin Roosevelt` or `Eleanor Roosevelt` in a case sensitive manner and it should make concessions for middle names.
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
Then fix the code so that the regex that you have created is checked against `myString` and either `true` or `false` is returned depending on whether the regex matches.
2020-08-04 15:14:01 +08:00
2020-12-16 00:37:30 -07:00
# --hints--
2020-08-04 15:14:01 +08:00
2021-02-06 04:42:36 +00:00
Your regex `myRegex` should return `true` for the string `Franklin D. Roosevelt`
2020-08-04 15:14:01 +08:00
2020-12-16 00:37:30 -07:00
```js
myRegex.lastIndex = 0;
assert(myRegex.test('Franklin D. Roosevelt'));
```
2021-02-06 04:42:36 +00:00
Your regex `myRegex` should return `true` for the string `Eleanor Roosevelt`
2020-08-04 15:14:01 +08:00
```js
2020-12-16 00:37:30 -07:00
myRegex.lastIndex = 0;
assert(myRegex.test('Eleanor Roosevelt'));
2020-08-04 15:14:01 +08:00
```
2021-02-06 04:42:36 +00:00
Your regex `myRegex` should return `false` for the string `Franklin Rosevelt`
2020-08-04 15:14:01 +08:00
2020-12-16 00:37:30 -07:00
```js
myRegex.lastIndex = 0;
assert(!myRegex.test('Franklin Rosevelt'));
```
2020-08-04 15:14:01 +08:00
2021-02-06 04:42:36 +00:00
Your regex `myRegex` should return `false` for the string `Frank Roosevelt`
```js
myRegex.lastIndex = 0;
assert(!myRegex.test('Frank Roosevelt'));
```
You should use `.test()` to test the regex.
2020-08-04 15:14:01 +08:00
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/myRegex.test\(\s*myString\s*\)/));
```
2020-08-04 15:14:01 +08:00
2021-02-06 04:42:36 +00:00
Your result should return `true` .
2020-08-04 15:14:01 +08:00
```js
2020-12-16 00:37:30 -07:00
assert(result === true);
2020-08-04 15:14:01 +08:00
```
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```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
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);
```