Match Characters that Occur Zero or More Times-gt

Match Characters that Occur Zero or More Times-gt
0

Tell us what’s happening:
Can someone explain why we get null in the oPhrase match. It does contain “o” which is mentioned in our regex. So when we use “*” it needs to match both characters to give us a match , it can’t match just either 1 of the two characters?

Your code so far


let soccerWord = "gooooooooal!";
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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 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

oPhrase is “over the moon”. If the regex is /go*/ then the string must have a single “g” followed by zero or more "o"s. There is no “g” in “over the moon”.

1 Like

Alright got it , thanks for your explanation!