Recall & Review
beginner
What does the character class
[a-z] represent in Ruby regular expressions?It matches any single lowercase letter from
a to z.Click to reveal answer
beginner
What does the pattern
\d match in Ruby regular expressions?It matches any single digit character, equivalent to
[0-9].Click to reveal answer
intermediate
Explain the difference between
\w and \W in Ruby regex.\w matches any word character (letters, digits, and underscore), while \W matches any character that is NOT a word character.Click to reveal answer
beginner
What does the pattern
\s match in Ruby regular expressions?It matches any whitespace character, including spaces, tabs, and newline characters.
Click to reveal answer
beginner
How do you match any character except a newline in Ruby regex?
Use the dot
. character, which matches any character except newline by default.Click to reveal answer
Which pattern matches any uppercase letter in Ruby regex?
✗ Incorrect
The pattern
[A-Z] matches any uppercase letter from A to Z.What does the pattern
\D match?✗ Incorrect
\D matches any character that is NOT a digit.Which pattern matches a whitespace character?
✗ Incorrect
\s matches any whitespace character like space, tab, or newline.What does the pattern
[^a-z] mean?✗ Incorrect
The caret
^ inside brackets negates the class, so it matches any character except lowercase letters.Which pattern matches any word character?
✗ Incorrect
\w matches letters, digits, and underscore characters.Describe the common character classes used in Ruby regular expressions and give an example of each.
Think about digits, letters, and spaces.
You got /5 concepts.
Explain how to use negation inside character classes in Ruby regex and provide an example pattern.
Negation flips what the class matches.
You got /3 concepts.