Regex: Mixed Groupings Characters: Why did I pass?

Tell us what’s happening:
I was able to pass this checkpoint with the code below. When I took a closer look, it doesn’t seem to make sense, is it a bug?

My initial thinking was that “?” would mean that any character (middle initial) following “Franklin” or “Eleanor” is optional. But in actuality, “?” only means that “Franklin” or “Eleanor” is optional. Not sure why this would allow me to pass since I would be leaving out keys parts of the name.

Your code so far

let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor)? Roosevelt/; // Change this line
let result = myRegex.test(myString); // 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/79.0.3945.117 Safari/537.36.

Challenge: Check For Mixed Grouping of Characters

Link to the challenge:

? means that it is able to match any 0 or 1 string after either Franklin or Eleanor.

The answer is right.

it is because you have nothing that say that the match should start at the start of the string
so when there is a middle initial the regex is just finding " Roosevelt" and that’s fine for it
it seems the tests work the same with this

Ah, I see. But isn’t this a flaw/bug? Should it not exactly match the three different names? Just “Roosevelt” is only part of the name.

It does appear to be a bug. Would you mind reporting it on our GitHub tracker? Please provide all relevant details, so someone can review and work on the issue.

Thank you.

Reported on the GitHub tracker.

1 Like