Match Characters that Occur Zero or More Times struggle

Match Characters that Occur Zero or More Times struggle
0

#1

Tell us what’s happening:
I dont understand where I’m wrong. Can sb help me? thanks in advance.

Your code so far


let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /A*/gi; // 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/69.0.3497.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


#2

When I was going through these challenges I found that using a regular expression testing tool really helped.

This one works well

Your expression correctly matches all A and a characters in chewieQuote. However the challenge has 2 checks to make sure that your expression realistically only matches “Aaa…”, it should not match " a " alone.

My solution:

let chewieRegex = /A[a]*/; // Change this line

Will not need any flags and looks for instances of “A” which is immediately followed by 0 or more “a”


#3

Thank you for your answer. It was correct. But can you explaint more detail? Why did you put a lowercase “a” inside of square bracket?