Possible bug in Regex lesson?

In the lesson Regular Expressions: Match Characters that Occur Zero or More Times
URL: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-characters-that-occur-zero-or-more-times

the task is to come up with a regex that will match all upper and lower "a" characters using the * character.

I believe the regex that fulfills this condition is /a*/gi. When I use it, it doesn’t pass the test.

The feedback I get is:

Am I missing something?

The challenge is a little confusing. Really, the best regex to solve it would be /a{2,}/i, or perhaps /aa+/i (match 2 or more “a”s, case insensitive), but that fails the first condition (must use the * character).

It might help to think of the challenge this way:

  • It must match at least 2 “a”s.
  • After that, it can match 0 or more “a”s (this makes no difference to how the regex functions, but is necessary to pass the first test case).
1 Like

I believe that usage of curly braces in regex is not covered yet before this challenge (if you go through the challenges by order of appearance in the curriculum).

If that is the case, I think the challenge description should be updated to make it more clear., or at least change the challenge’s content to match what it teaches…

To be clear, the /a{2,}/i solution isn’t how to pass the challenge, although a valid solution can include curly-brace notation. That’s just what I’d consider to be the best/clearest solution if you needed a regex to do this in production code (maybe for some sort of wookie-themed natural language processing app? :joy:)

The code and copy for the fCC challenges is all open source and written by volunteers, and contributions are welcome. I agree it’s somewhat confusing, so I’m opening an issue on the GitHub repo now.

Yes I understood that, all I’m saying is that the challenge, it’s description or it’s solution test need to be rewritten.

I tried to clone the FCC repo and the curriculum repo to fix a different bug, but ran into problems.
There is a known bug happening with running FCC locally, and I understood from other people in the Contributors’ Gitters chat room that it’s being addressed.

I also tried to commit a change and ran into problems with that…

use this /Aa*/; it will complete all the conditions.

1 Like

Try http://regexr.com/ and paste your pattern, and apply the flags, and put sample text there to see. :slightly_smiling_face: The lower part says that it shouldn’t detect anything.

Do you know why the /a*/i not working?
I logged out and returns "". Why is that?


i am not perfect in JavaScript but here if you do /a*/i , it only search for matching AAAAAAA or aaaaa not match Aaaaa or aAAAAA so you have to add one A in Aaaaaa or a in aAAAAA . i think you got it

1 Like

Thank you for your help.
Now I see the differences.