Match Characters that Occur Zero or More Times HELP

what am i doing wrong here

Your code so far


let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /a*/; // Change this line
let result = chewieQuote.match(chewieRegex);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 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

1 Like

a* matches nothing (0 or more)
try +

remember that regextester I suggested you use to check? Here’s what you would have seen if you had tested your regex there:

but then i am supposed to be matching in this lesson using *

ok, so perhaps you need to match the first letter first exactly and then the rest of the a’s less specifically (with the star). Give it a try on regextester till you get the hang of it…

i tried using gi flags,first three tests are passed but they said in the lesson that it does not need flags

1 Like

right, no flag is needed.

Think about how to match this exact string.
It start with an A…

Hope this is enough clue. And I really do suggest you try the regextester

okay got it i used Aa to pass the test but it shouldnt have passed because the other test says do not match it with a line that has a in it and in the example code they extracted g even after putting in /go*/. i dont get it

the reason /go*/ matches a ‘g’ or a ‘go’ or a ‘gooooo’ is because it actually looks for

one g and
zero or more o

so therefore
‘g’ has one g and zero o
‘go’ has one g and one o
‘goooo’ has one g and 4 os

4 Likes

so if the condition of matching A is not met it stops checking for a* ?

yes correct Aa* will only match ‘A’ or ‘Aa’ or ‘Aaa’ etc.

For this problem, the ‘Aa’ also helps distinguish the difference between a single ‘a’ vs. ‘Aaaaaaargh’

Another way to look at it, if I’m not stabbing a dead body.

To regular expressions: ‘A’ is a completely different from ‘a’. They are two distinct characters to search for.

1 Like

The question don’t allow to use regex flag so the simple answer is Aaaaaaaaaaaaaaaa*

The instructions are unfortunately not very clear on the problem. I totally get the disconnect as I faced it as well.
To,possibly, help clarify the instructions…they want you to identify the capital “A” followed by the other ‘a’’ characters that follow.-not simply any "a"s in any random quote.
Maybe that could help.
I feel your pain though my friend.
Happy Coding!

7 Likes

For everyone still wondering and going against the walls try doing the regex with Aaa …


let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /Aaa*/gi; // Change this line
let result = chewieQuote.match(chewieRegex);
2 Likes

@Elthask
Yes, but the instructions say “you do not need flags”.
And it seems like, by mistake, you typed the lowercase a two times.

So ~~>

/Aa*/; 

is all you need. :grin:

I don’t even know what you did wrong, but I think you definitely have something to improve.

i still don’t get it :frowning: :cold_sweat:

Directions:

Create a regex chewieRegex that uses the * character to match all the upper and lower "a" characters in chewieQuote. Your regex does not need flags, and it should not match any of the other quotes.

This problem is worded incorrectly.

You do not match all upper and lower 'a’s. You need to match Aa combination which could have any number of additional lower 'a's

So like. Aa, Aaaa, Aaaaaaa, Aaaa you would match.

A{1,3} means minimum number As present is 1, and the max number of As in a row is 3.
A{4,8} means minimum number As present is 4, and the max number of As in a row is 8.
A{4,} means minimum number As present is 4, and the max number of As in a row is infinite.

A{0,} means minimum number As present is 0, and the max number of As in a row is infinite.

A{0,} and A* are the same thing.
just like
A{1,} and A+ are the same thing.