Bird
0
0

How do you correctly use Ruby's scan method to extract all lowercase letters from a string text?

easy📝 Syntax Q3 of 15
Ruby - Regular Expressions
How do you correctly use Ruby's scan method to extract all lowercase letters from a string text?
Atext.scan(/\d+/)
Btext.scan(/[a-z]/)
Ctext.scan(/[A-Z]/)
Dtext.scan(/\w+/)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the pattern

    We want to find all lowercase letters, which are represented by the character class [a-z].
  2. Step 2: Use scan with regex

    The scan method takes a regex and returns all matches. Using /[a-z]/ will find each lowercase letter.
  3. Final Answer:

    text.scan(/[a-z]/) -> Option B
  4. Quick Check:

    Check if output contains only lowercase letters. [OK]
Quick Trick: Use /[a-z]/ to match all lowercase letters [OK]
Common Mistakes:
  • Using \d+ which matches digits, not letters
  • Using uppercase range [A-Z] instead of lowercase
  • Using \w+ which matches letters, digits, and underscore

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes