210-255 · Question #171
Which regex matches on all lowercase letters only?
The correct answer is C. [a-z]+. The regex [a-z]+ uses a character class to match one or more lowercase ASCII letters exclusively.
Question
Which regex matches on all lowercase letters only?
Options
- A[a-z]+
- Ba*z+
- C[a-z]+
- Da-z+
How the community answered
(47 responses)- A4% (2)
- B2% (1)
- C94% (44)
Why each option
The regex [a-z]+ uses a character class to match one or more lowercase ASCII letters exclusively.
Although visually similar, this option contains non-standard or improperly encoded bracket characters that would not be interpreted correctly as a regex character class by standard engines.
a*z+ matches zero or more literal 'a' characters followed by one or more literal 'z' characters, not a range of lowercase letters.
The pattern [a-z]+ defines a character class spanning all lowercase letters from 'a' to 'z' and the '+' quantifier requires one or more matches, ensuring the entire match consists solely of lowercase letters. This is the standard, correct regex syntax for this purpose.
a-z+ treats 'a-z' as a literal string sequence outside of brackets and applies '+' only to 'z', so it does not define a character class and does not match all lowercase letters.
Concept tested: Regex character class syntax for lowercase matching
Source: https://www.regular-expressions.info/charclass.html
Topics
Community Discussion
No community discussion yet for this question.