Bird
0
0

What is the correct way to write a regex literal in Ruby to match the word cat?

easy📝 Conceptual Q11 of 15
Ruby - Regular Expressions
What is the correct way to write a regex literal in Ruby to match the word cat?
Aregex('cat')
B"cat"
C'cat'
D/cat/
Step-by-Step Solution
Solution:
  1. Step 1: Understand regex literal syntax

    In Ruby, regex literals are written between slashes, like /pattern/.
  2. Step 2: Identify the correct pattern for 'cat'

    The pattern to match the word 'cat' is simply /cat/.
  3. Final Answer:

    /cat/ -> Option D
  4. Quick Check:

    Regex literal = /pattern/ [OK]
Quick Trick: Regex literals always use slashes /pattern/ in Ruby [OK]
Common Mistakes:
  • Using quotes instead of slashes
  • Calling a non-existent regex() function
  • Confusing string and regex syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes