Match Characters that Occur Zero or More Times

Match Characters that Occur Zero or More Times
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!


#4

I do not see his three backstick. What are you talking about sir?
Could you give example for using one backstick for inline code and block of code?

For my understanding it should match all the a’s but no any other characters.
so I did try
1. let chewieRegex = /a*/g;
2. let chewieRegex = /a*[^.]/g;
obviously both would not work. I am not really sure where do go from here.


#5

@kevinSmith was referring to how to post code on the forum and not anything to do with the challenge code.


#6

Randel is correct, but answering your question…

It’s hard to show because you can’t show backticks without some difficulty. Imagine that the % is the backtick. An example of block code would be:

%%%
const blockCode = 3
blockCode++
%%%

Or for inline code:

I prefer to use %i++% instead of a %i=i+1% or %i+=1%.

It puts it in a slightly different font, but more importantly, it doesn’t try to interpret the html but just renders the characters to the screen.