Match Characters that Occur Zero or More Times -- help

Tell us what’s happening:

In the instructions example below why does the gPhrase.match(goRexex); returns [“g”]? Shouldn’t it return null cause the check was for “go”.

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 code so far


let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /Aa*/;
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:

In the instructions example below why does the gPhrase.match(goRexex); returns [“g”]?

It’s go *
The asterisk means 0 or more, hence it will match g, go, goo, etc^^

2 Likes

hello dear ,me too at the beginnig that was for me not abvious , but the answer is right .
let goRegex = /go*/; means match every(g) followed by zero number of the letter (o) or more ,that’s why the answer was g , so g is accepted because it is followed by zero letter .

1 Like