Bird
0
0

Which character class in Ruby regex matches any digit from 0 to 9?

easy📝 Conceptual Q1 of 15
Ruby - Regular Expressions
Which character class in Ruby regex matches any digit from 0 to 9?
A"\\D"
B"\\w"
C"\\s"
D"\\d"
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby regex character classes

    In Ruby regex, "\\d" matches any digit (0-9), "\\w" matches word characters, "\\s" matches whitespace, and "\\D" matches non-digits.
  2. Step 2: Identify the digit matching class

    Since the question asks for digits 0-9, "\\d" is the correct character class.
  3. Final Answer:

    "\\d" matches digits 0-9 -> Option D
  4. Quick Check:

    Digit class = "\\d" [OK]
Quick Trick: Digits are matched by \d in Ruby regex [OK]
Common Mistakes:
  • Confusing \w (word chars) with \d (digits)
  • Using \D which matches non-digits
  • Mistaking \s (spaces) for digits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes