Just a quick question about Regex

Tell us what’s happening:
Hello all, just a quick question about using * in a regex.
why is it that when I have a pattern that has something repeating zero or more times like in:
let test = “aaaaaaargh”;
And I use a regex such as:
let regex = /a*/gi;

it will show me the expression I was looking for with a bunch of empty strings when I print it to the console?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

Challenge: Match Characters that Occur Zero or More Times

Link to the challenge:

a* means zero or more a
it happens many times that you have 0 a, so empty strings can happen
you need to be more specific in your regex

like, read again what you are asked to d

Create a regex chewieRegex that uses the * character to match an uppercase "A" character immediately followed by zero or more lowercase "a" characters in chewieQuote . Your regex does not need flags or character classes, and it should not match any of the other quotes.

1 Like