Regular Expressions: Match Letters of the Alphabet

Regular Expressions: Match Letters of the Alphabet
0.0 0

#1

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.

My code:


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

Result:

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

// running test
Your regex should not match any characters in “He made a fair move. Screaming about it can&#39t help you.”
Your regex should not match any characters in “Let him have it. It&#39s not wise to upset a Wookiee.”
// tests completed

… I have no idea where the last two cases are coming from. Is this a bug from a previous version of this question?


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

Your regex isn’t doing what you think it is

  • a
    • match the lowercase case ‘a’ specifically
  • aA
    • match the lowercase ‘a’
    • followed directly by a capital ‘A’
  • aA*
    • match the lowercase ‘a’
    • followed directly by a capital ‘A’ 0 or more times
EG.
  • “He made a fair move…”
    • matches the ‘a’ in made, since capital ‘A’ can match 0 times

#5

Do you know where:

Your regex should not match any characters in “He made a fair move. Screaming about it can’t help you.”
Your regex should not match any characters in “Let him have it. It’s not wise to upset a Wookiee.”

… are coming from? The first line of code offers:

let chewieQuote = “Aaaaaaaaaaaaaaaarrrgh!”;

… but there are no mentions of the other two strings.


#6

All I needed to do was remove gi from the declaration and apply your adjustment.

let chewieRegex = /Aa*/;