freeCodeCampBeta Regular Expressions: Match Characters that Occur Zero or More Times

Hello, i don’t know if it’s an error or me but i’m having trouble with this exercice.
Link: https://beta.freecodecamp.org/en/challenges/regular-expressions/match-characters-that-occur-zero-or-more-times

My code:

let starWars = "Star Wars";
let starWarsRegex = /Star Wars.*/gi;
let result = starWars.match( starWarsRegex );

Your regex should match “Star Wars: The Phantom Menace”. OK
Your regex should match “Star Wars: Attack of the Clones”. NOT OK
Your regex should match “Star Wars: Revenge of the Sith”. OK
Your regex should match “Star Wars: A New Hope”. NOT OK
Your regex should match “Star Wars: The Empire Strikes Back”. OK
Your regex should match “Star Wars: Return of the Jedi”. NOT OK
Your regex should match “Star Wars: The Force Awakens”. OK
Your regex should not match “The Clone Wars” OK

Thanks !

The instructions say your regex doesn’t need flags

1 Like

:confused: ok, my fault. Good day to you

Hi, I’m having the same trouble with the current version of the challenge.

My solution has been: let chewieRegex = /[aA]*/;

But it doesn’t pass the last two tests :frowning: Could anybody help me?

You shouldn’t use brackets, since it will also match single 'a' characters.

Using just /a*/ doesn’t even match the long string of 'a's in 'Aaaaaaaaaaaaaargh' and I’m totally confused why it doesn’t match.

1 Like

Hi! Did you ever figure this out? I tried: /a*/ like you but nothing.

It starts matching from the beginning of the string and it indeed finds a* there: the empty substring just before A matches that.

let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
let chewieRegex = /A[a]*/; // Change this line
let result = chewieQuote.match(chewieRegex);
13 Likes

We can’t use flags to accept capital letter (ie ‘A’), so running /Aa*/ should catch both the first capital ‘A’ and the duplicated ‘a’-s that follow.

let chewieQuote = “Aaaaaaaaaaaaaaaarrrgh!”;
let chewieRegex = /Aa*/; // Change this line
let result = chewieQuote.match(chewieRegex);

16 Likes

This is awesome man. sometimes they did not say it clearly

let chewieQuote = “Aaaaaaaaaaaaaaaarrrgh!”;
let chewieRegex = /A[a]*/; // Change this line
let result = chewieQuote.match(chewieRegex);

2 Likes

Definitely your answer is correct one, tnx.

just match with Aa*
it will help you

1 Like

image

In this same lesson, why the third one returns null? I get that there are no "g"s, pero there are some “o” letters on the string… I guess I’m not getting this yet…

The reason why the third one returns null is that even if there is an ‘o’ or not, it must be preceded by a ‘g.’ The 'o’s in the string “Over the moon” don’t come after a ‘g.’

1 Like