Why is it matching this?

Why is it that “gut feeling” is returning “g” if the regex is /go*/ ?
Shouldn’t it least have a “go” (both letters)? or how come it matches if “gut feeling” doesn’t have a “go”, but “gu”. Shouldn’t it return null?


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

Challenge: Match Characters that Occur Zero or More Times

Link to the challenge:

* means - match 0 or more of the preceding token.

1 Like

Thank you so much,
God, I´m so dumb.
For some reason, I thought it affected the character AFTER the asterisk.
Now it makes sense. Thank you again!!