Bird
0
0

Which Ruby regular expression pattern matches any single digit character?

easy📝 Conceptual Q11 of 15
Ruby - Regular Expressions
Which Ruby regular expression pattern matches any single digit character?
A/\D/
B/\d/
C/\s/
D/\w/
Step-by-Step Solution
Solution:
  1. Step 1: Understand \d in Ruby regex

    The pattern \d matches any digit character (0-9).
  2. Step 2: Compare with other options

    \w matches word characters (letters, digits, underscore), \s matches whitespace, \D matches non-digit characters.
  3. Final Answer:

    /\d/ -> Option B
  4. Quick Check:

    Digit pattern = /\d/ [OK]
Quick Trick: Remember \d means digit, \w means word character [OK]
Common Mistakes:
  • Confusing \d with \w
  • Using /\D/ which matches non-digits
  • Thinking \s matches digits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes