Match Characters that Occur Zero or More Times

Match Characters that Occur Zero or More Times
0.0 0

#1

Tell us what’s happening:

Your code so far


let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /Aa*/; // Change this line
let result = chewieQuote.match(chewieRegex);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times

What I don’t understand is the code from instruction.

let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex); // Returns ["goooooooo"]
gPhrase.match(goRegex); // Returns ["g"]
oPhrase.match(goRegex); // Returns null```

Why let gPhrase = "gut feeling"; match a g while let oPhrase = "over the moon"; matchs nothing?


#2

FIrst of all, for inline code samples, please use one backtick, not three. Three is for blocks of code. I edited your post for readability.

OK, you’re asking why

let oPhrase = "over the moon";
let goRegex = /go*/;
oPhrase.match(goRegex); // Returns null```

returns null?

The goRegex is looking for a ‘g’ followed by zero or more ‘o’. In the phrase over the moon, there is no ‘g’.


#3

I see! I understood the meaning wrong. Thank you!