Regular Expressions: Check For Mixed Grouping of Characters - Better Solution?

Tell us what’s happening:

Regular Expressions: Check For Mixed Grouping of Characters

The answer for the question is:
let myRegex = /(Franklin|Eleanor).*Roosevelt/;

Wouldn’t a better answer be the below to account for the spacing? Otherwise even “EleanorRoosevelt” would be accepted as True.
let myRegex = /(Franklin|Eleanor)\s(.*)Roosevelt/;

Your code so far


let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0.

Challenge: Check For Mixed Grouping of Characters

Link to the challenge:

You’re right, but the challenge just wants you to check if it is Eleanor or Franklin Roosevelt. It doesn’t really ask if the whitespace is important.
But you are right.

1 Like

Thanks. You are correct the challenge doesn’t ask for it but wanted to check for my own knowledge.

1 Like

It also does not verify that the name begins with Franklin or Eleanor. Would be better with ^ at the start or would be true for DeFranklin.