0
0
Rubyprogramming~15 mins

Common patterns and character classes in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Common patterns and character classes
📖 Scenario: You are working on a simple text processing tool that needs to find specific patterns in a string. This is useful for searching and validating text like phone numbers, emails, or codes.
🎯 Goal: Build a Ruby program that uses regular expressions with common patterns and character classes to find all vowels in a given string.
📋 What You'll Learn
Create a string variable with a specific sentence.
Create a regular expression pattern using character classes to match vowels.
Use the pattern to find all vowels in the string.
Print the list of vowels found.
💡 Why This Matters
🌍 Real World
Finding patterns like vowels, digits, or specific characters is common in text processing, data validation, and search features.
💼 Career
Understanding regular expressions and character classes is essential for roles in software development, data analysis, and quality assurance.
Progress0 / 4 steps
1
Create the text string
Create a string variable called text and set it to the exact value "Hello, Ruby learners!".
Ruby
Need a hint?

Use double quotes to create the string exactly as shown.

2
Create a vowel pattern
Create a regular expression variable called vowel_pattern that matches any vowel character (a, e, i, o, u) using a character class. Use the pattern /[aeiou]/i to match vowels case-insensitively.
Ruby
Need a hint?

Use square brackets [] to create a character class and add i after the slash for case-insensitive matching.

3
Find all vowels in the text
Use the scan method on text with vowel_pattern to find all vowels. Store the result in a variable called vowels.
Ruby
Need a hint?

The scan method returns all matches as an array.

4
Print the vowels found
Print the vowels array using puts vowels.inspect to show all vowels found in the text.
Ruby
Need a hint?

Use puts vowels.inspect to print the array in a readable format.