Bird
0
0

How can you use the match operator to find the position of the first vowel in the string "rhythm", considering vowels as a, e, i, o, u, y?

hard📝 Application Q9 of 15
Ruby - Regular Expressions
How can you use the match operator to find the position of the first vowel in the string "rhythm", considering vowels as a, e, i, o, u, y?
A"rhythm" =~ /[aeiou]/
B"rhythm" =~ /[xz]/
C"rhythm" =~ /vowels/
D"rhythm" =~ /[aeiouy]/
Step-by-Step Solution
Solution:
  1. Step 1: Identify vowels in the string

    "rhythm" has no standard vowels but has 'y' acting as vowel.
  2. Step 2: Use regex including 'y' to find first vowel

    "rhythm" =~ /[aeiouy]/ includes 'y' in the vowel set, so it matches at index 2.
  3. Final Answer:

    "rhythm" =~ /[aeiouy]/ -> Option D
  4. Quick Check:

    Include 'y' for vowel match in this word [OK]
Quick Trick: Add 'y' to vowel set for words like 'rhythm' [OK]
Common Mistakes:
  • Ignoring 'y' as vowel in some words
  • Using wrong character classes
  • Expecting match with 'vowels' literal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes