Ruby - Regular ExpressionsHow can you use regex in Ruby to replace all vowels in a string with '*'?Astring.gsub(/[aeiou]/i, '*')Bstring.replace(/[aeiou]/, '*')Cstring.sub(/[aeiou]/, '*')Dstring.match(/[aeiou]/).replace('*')Check Answer
Step-by-Step SolutionSolution:Step 1: Identify method to replace all matchesgsub replaces all occurrences matching regex in the string.Step 2: Use regex for vowels with case-insensitive flag/[aeiou]/i matches all vowels regardless of case.Step 3: Combine to replace vowels with '*'string.gsub(/[aeiou]/i, '*') replaces all vowels with '*'.Final Answer:string.gsub(/[aeiou]/i, '*') -> Option AQuick Check:Replace vowels = gsub with /[aeiou]/i [OK]Quick Trick: Use gsub with /[aeiou]/i to replace all vowels [OK]Common Mistakes:Using sub replaces only first matchUsing replace method incorrectlyTrying to call replace on match object
Master "Regular Expressions" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Advanced Metaprogramming - Inherited hook - Quiz 7medium Concurrent Programming - GIL (Global Interpreter Lock) impact - Quiz 2easy Concurrent Programming - Thread safety concepts - Quiz 10hard Functional Patterns in Ruby - Proc composition - Quiz 5medium Gems and Bundler - Bundler for dependency resolution - Quiz 9hard Gems and Bundler - Bundler for dependency resolution - Quiz 14medium Ruby Ecosystem and Best Practices - Ruby style guide essentials - Quiz 12easy Ruby Ecosystem and Best Practices - Debugging with pry and byebug - Quiz 7medium Testing with RSpec and Minitest - RSpec describe and it blocks - Quiz 4medium Testing with RSpec and Minitest - Let and before hooks - Quiz 11easy