Bird
0
0

Identify the error in this Ruby regex:

medium📝 Debug Q6 of 15
Ruby - Regular Expressions
Identify the error in this Ruby regex:
/[a-z{3,5}]/
AMissing escape for curly braces
BCurly braces are inside character class incorrectly
CRange a-z is invalid
DNo error, regex is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand quantifiers and character classes

    Curly braces {3,5} are quantifiers and should be outside character classes []. Inside [] they are treated as literal characters.
  2. Step 2: Identify the error in placement

    Putting {3,5} inside [] is incorrect syntax. It should be /[a-z]{3,5}/ to match 3 to 5 lowercase letters.
  3. Final Answer:

    Curly braces quantifier is incorrectly placed inside character class -> Option B
  4. Quick Check:

    Quantifiers go outside [] in regex [OK]
Quick Trick: Quantifiers like {3,5} must be outside character classes [OK]
Common Mistakes:
  • Placing quantifiers inside []
  • Not escaping special characters when needed
  • Confusing character class syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes