Regular Expressions - Please help me understand the * symbol

Regular Expressions - Please help me understand the * symbol
0.0 0


The * symbol matches characters that occur zero or more times. I have a hard time understanding the practical application of it. If it looks for matches that occur zero or more times, wouldn’t it match everything? After all, everything will match at least zero times. One of the examples used in the challenge was matching /go*/ in the string “over the moon” and it returns null. Why does it return null if “go” is in the sentence at least zero times (ie, it’s not in the sentence)? I’m sorry if this is a stupid question but it’s really bugging me and searching match zero or more times js regex on Google doesn’t seem to yield the explanation I’m looking for.


* is only a modifier for the regular expression bit beforehand. To match everything you’d use .* (anything any amount of times).

go* matches g (implicitly once) followed by o (zero or more times). There is no g in that string. You would need to group the characters for the modifier to apply to both.


I’m amazed by your lightning-speed response and the simplicity of the explanation :smiley: Thank you so much!