Hi guys, what did you do to pass this test?
I read the MDN Regex documentation above and still unable to solve this problem. Below is my code:
let quoteSample = "The five boxing wizards jump quickly.";
//let quoteSample = "Pack my box with five dozen liquor jugs.";
let alphabetRegexV2 = /\w+/gi; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
And here is the errors I’ve got:
// running test
Your regex should find 31 alphanumeric characters in “The five boxing wizards jump quickly.”
Your regex should find 32 alphanumeric characters in “Pack my box with five dozen liquor jugs.”
Your regex should find 30 alphanumeric characters in “How vexingly quick daft zebras jump!”
Your regex should find 36 alphanumeric characters in “123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.”
// tests completed
Any suggestion is appreciated. Thanks a bunch guys.
Why are you using the + in your regular expression? Do you understand what that means?
Thank you for the hint. I keep thinking + means in case the character repeats itself, the search still counts the repeated character towards the result. Does it mean + only counts when a character repeats itself, like “aa” is counted but “a” is not? And that’s why my above code did not work?
I simply removed + and the beloved popup showed up.
- means match 1 or more of the previous character. So, when you write /\w+/g, that means match 1 or more word characters (which include any letter, number and the underscore character). Basically, it will match full words. So in this case, it matches 6 words.
When you leave off the +, then you are only going to be matching single word characters. So, the spaces and punctuation would not be counted.
Ah, thank you for your explanation.