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

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

#1

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 !


#2

The instructions say your regex doesn’t need flags


#3

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


#4

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?


#5

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.


#6

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


#7

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


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

#9

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);


#10

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


#11

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


#12

Definitely your answer is correct one, tnx.