well, the test method will tell if there is part of the string that correspond to the pattern, pass99 correspond to the pattern, so it returns true.
Maybe you want to specify where the match should start?
if the test method search for a substring that matches the pattern, you need to anchor the pattern to the beginning and/or end of the string, to be sure that it is not just a random portion in the middle that pass, but the whole string
pass99 is a substring that matches the pattern, but if you anchor the pattern to the beginning of the string, the substring that matches must start at the beginning.
There are these nice things called anchors… they are uber useful.
After looking at the solution, I found that the second part needs \w*. Why?
I tried looking all over the internet for why a two-part regex would need \w*\d{2} to satisfy the requirement that there are at least two consecutive digits and that there are at least 5 characters and that it starts with a non-digit.
what does the \w* do? in this instance? it seems like /^D(?=\w{5})(?=d{2})/ satisfies all that. I passed the test, but I just don’t understand why it passes with the \w* added to the beginning of the second part of the regex.
I was really stuck here and I still don’t understand why it’s necessary to use
(?=\w+\d{2}) instead of
(?=\D+\d{2}).
I am checking with ^\D at the beginning, then the length (works fine) but I do not understand why 1) works with all the strings and 2) does not match the “astr1on11aut” case.