Scan for all matches
📖 Scenario: Imagine you have a paragraph of text and you want to find all the words that start with the letter 'a'. This is useful when you want to highlight or count specific words in a text.
🎯 Goal: You will write a Ruby program that uses the scan method to find all words starting with the letter 'a' in a given string.
📋 What You'll Learn
Create a string variable called
text with the exact sentence: "An apple a day keeps the doctor away."Create a regular expression variable called
pattern that matches words starting with the letter 'a' (case insensitive).Use the
scan method on text with pattern to find all matching words and store them in a variable called matches.Print the
matches array.💡 Why This Matters
🌍 Real World
Finding all matches in text is useful for searching, filtering, or analyzing data like emails, logs, or documents.
💼 Career
Many programming jobs require text processing skills, including using regular expressions to extract information efficiently.
Progress0 / 4 steps