2.7 KiB
2.7 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
5c3dda8b4d8df89bea71600f | Check For Mixed Grouping of Characters | 1 | 301339 |
Description
()
.
If you want to find either Penguin
or Pumpkin
in a string, you can use the following Regular Expression: /P(engu|umpk)in/g
Then check whether the desired string groups are in the test string by using the test()
method.
let testStr = "Pumpkin";
let testRegex = /P(engu|umpk)in/;
testRegex.test(testStr);
// Returns true
Instructions
Franklin Roosevelt
or Eleanor Roosevelt
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 myString
and either true
or false
is returned depending on whether the regex matches.
Tests
tests:
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Franklin D. Roosevelt</code>
testString: myRegex.lastIndex = 0; assert(myRegex.test('Franklin D. Roosevelt'));
- text: Your regex <code>myRegex</code> should return <code>true</code> for the string <code>Eleanor Roosevelt</code>
testString: myRegex.lastIndex = 0; assert(myRegex.test('Eleanor Roosevelt'));
- text: Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Franklin Rosevelt</code>
testString: myRegex.lastIndex = 0; assert(!myRegex.test('Franklin Rosevelt'));
- text: Your regex <code>myRegex</code> should return <code>false</code> for the string <code>Frank Roosevelt</code>
testString: myRegex.lastIndex = 0; assert(!myRegex.test('Frank Roosevelt'));
- text: You should use <code>.test()</code> to test the regex.
testString: assert(code.match(/myRegex.test\(\s*myString\s*\)/));
- text: Your result should return <code>true</code>.
testString: assert(result === true);
Challenge Seed
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
Solution
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);