What's the difference between ().* and () .* with space in Regex? Why does the one with space cannot pass the challenge?

Tell us what’s happening:
Describe your issue in detail here.

I answered /(Franklin|Eleanor) .* Roosevelt/ on the challenge but it cannot pass. Shouldn’t it be correct because Franklin and D. has a space in between? Why does the .* should be connected to (Franklin|Eleanor)?

Your code so far

let myString = "Franklin D. Roosevelt";
let myRegex = /(Franklin|Eleanor) .* Roosevelt/; // Change this line
let result = myRegex.test(myString); // Change this line
let match  = myString.match(myRegex); // Change this line
// After passing the challenge experiment with myString and see how the grouping works


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Check For Mixed Grouping of Characters

Link to the challenge:

RegEx doesn’t know spacing - if you add a space, it will look for a space.
In your example, you have two spaces plus any number of characters inbetween. So it will not match strings which have less than two spaces inbetween the Names.
Looking at the test cases shows Frankling Roosevelt with only one space between → your RegEx will fail here.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.