question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regular Expressions - asterisk

See original GitHub issue

Describe your problem and - if possible - how to reproduce it

I find this challenge’s instructions pretty confusing. I made the hard part bold.

The last challenge used the plus + sign to look for characters that occur one or more times. There’s also an option that matches characters that occur zero or more times.

The character to do this is the asterisk or star: *.

let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex); // Returns ["goooooooo"]
gPhrase.match(goRegex); // Returns ["g"]
oPhrase.match(goRegex); // Returns null

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.

somehow this worked:

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

Here are tests:

  1. Your regex chewieRegex should use the * character to match zero or more a characters.
  2. Your regex chewieRegex should match 16 characters.
  3. Your regex should match “Aaaaaaaaaaaaaaaa”.
  4. Your regex should not match any characters in “He made a fair move. Screaming about it can’t help you.”
  5. Your regex should not match any characters in “Let him have it. It’s not wise to upset a Wookiee.”

4th test is especially confusing. there are lowercase ‘a’, why should I not(added after edit) match them?

Add a Link to the page with the problem

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

5reactions
JESiicommented, Sep 15, 2018

@scissorsneedfoodtoo This bug has nothing to do with the asterisk being tricky. It has to do with the fact that the instructions are just plain wrong.

The instructions say:

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 means a RegEx like /[Aa]*/g

What the instructions should say is:

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

Now we get to the desired RegEx of /A[Aa]*/g

3reactions
joker314commented, Oct 10, 2018

I’ll file a PR soon1 to resolve the issue of wording.

1 - 0 to 2 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Read and Use Regular Expressions | Hall
The asterisk is known as a repeater symbol, meaning the preceding character can be found 0 or more times. For example, the regular...
Read more >
Oracle Regular Expressions Pocket Reference [Book] - O'Reilly
The asterisk ( * ) is a quantifier that applies to the preceding regular expression element. It specifies that the preceding element may...
Read more >
Regular Expressions - Pages supplied by users
A regular expression followed by an asterisk ( * ) matches zero or more occurrences of the regular expression. If there is any...
Read more >
Asterisk in regex - Stack Overflow
1. $ by default means end of string. You might need MULTILINE flag if you want it to match end of line 2....
Read more >
Basic Regular Expressions: Kleene Star
The character * in a regular expression means "match the preceding character zero or many times". For example A* matches any number (including...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found