Match Characters that Occur Zero or More Times
Problem Explanation
Any letter in a regex expression that is followed by a *
does not have to occur in the string tested whereas any letter in a regex expression followed by a +
must occur in a string at least once, as shown below,
let phrase = "ba humbug";
let regexPlus = /bah+/;
let regexStar = /bah*/;
regexPlus.test(phrase); // returns false
regexStar.test(phrase); // returns true
Both allow for any number of occurrences of the same letter in a row, for example,
let phrase = "wooooow look at that!";
let regexPlus = /wo+w/;
let regexStar = /wo*w/;
regexPlus.test(phrase); // returns true
regexStar.test(phrase); // returns true
Solutions
Solution 1 (Click to Show/Hide)
let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /Aa*/; // Change this line
let result = chewieQuote.match(chewieRegex);