Tell us what’s happening:
So the problem is to match either Franklin D.Roosevelt or Eleanor Roosevelt with a single regex pattern. I was able to solve this with the following:
Your code so far
See the body below
My original code was
let myRegex = /(Franklin\sd.|Eleanor)\s\w*/i
This passed the challenge.
Anyhow, I wanted to play around with the code and see how the hints
solved the problem. So their solution was as follows:
let myString = "Eleanor Roosevelt"; let myRegex = /(Franklin|Eleanor).*Roosevelt/i; let result = myRegex.test(myString);
I was interested in this solution, using the wildcard with the asterisk to select
everything in between the first and last name would account for both the
middle initials and any spaces in between. I wanted to try and play around with
regex to see if I could shorten the code and get the same solution,
so I did this:
let myRegex = (Franklin|Eleanor).*\w*/i
This code failed a single test:
Your regex myRegex should return false for the string Franklin Rosevelt.
I thought that was fair, so I decided to change up my code up a bit, and this is
where it gets wierd for me:
let myRegex = (Franklin|Eleanor).*R\w*/i
This also fails the same test.
So next I decide to add a few more characters to see how things go:
let myRegex = (Franklin|Eleanor).*Roo\w*/i
This one passes for some reason. So I think okay…let me try shortening it
let myRegex = (Franklin|Eleanor).*Ro\w*/i
this one fails. I add the asterisk after Ro, I try adding a +,
neither pattern helps me to pass.
So can anyone help me understand this problem and what i’m doing wrong?
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