Ruby - Regular ExpressionsWhat is the correct way to write a regex literal in Ruby to match the word cat?Aregex('cat')B"cat"C'cat'D/cat/Check Answer
Step-by-Step SolutionSolution:Step 1: Understand regex literal syntaxIn Ruby, regex literals are written between slashes, like /pattern/.Step 2: Identify the correct pattern for 'cat'The pattern to match the word 'cat' is simply /cat/.Final Answer:/cat/ -> Option DQuick Check:Regex literal = /pattern/ [OK]Quick Trick: Regex literals always use slashes /pattern/ in Ruby [OK]Common Mistakes:Using quotes instead of slashesCalling a non-existent regex() functionConfusing string and regex syntax
Master "Regular Expressions" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Advanced Metaprogramming - Module_eval for dynamic behavior - Quiz 7medium Advanced Metaprogramming - Inherited hook - Quiz 12easy Concurrent Programming - Ractor for true parallelism - Quiz 3easy Concurrent Programming - Thread synchronization with Mutex - Quiz 7medium Gems and Bundler - Why gem management matters - Quiz 1easy Gems and Bundler - RubyGems repository - Quiz 2easy Regular Expressions - Capture groups - Quiz 8hard Ruby Ecosystem and Best Practices - Performance profiling basics - Quiz 11easy Ruby Ecosystem and Best Practices - Why conventions matter in Ruby - Quiz 7medium Ruby Ecosystem and Best Practices - Ruby version management (rbenv, rvm) - Quiz 5medium