Bird
0
0

Find the mistake in this code:

medium📝 Debug Q7 of 15
Ruby - Regular Expressions
Find the mistake in this code:
text = "abc def ghi"
matches = text.scan(/\w+)
puts matches.inspect
Ascan should be scan_all
Bputs.inspect is invalid
CRegex should be a string, not regex literal
DMissing closing slash in regex
Step-by-Step Solution
Solution:
  1. Step 1: Check regex syntax

    The regex /\w+ is missing the closing slash.
  2. Step 2: Identify syntax error

    Regex literals must start and end with slashes; missing slash causes error.
  3. Final Answer:

    Missing closing slash in regex -> Option D
  4. Quick Check:

    Regex literals need closing slash = B [OK]
Quick Trick: Regex literals must have opening and closing slashes [OK]
Common Mistakes:
  • Forgetting closing slash in regex
  • Using wrong method name
  • Misusing puts and inspect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes