Bird
0
0

You want to find all words starting with a or A in a string using a regex literal. Which regex literal correctly matches this requirement?

hard📝 Application Q15 of 15
Ruby - Regular Expressions
You want to find all words starting with a or A in a string using a regex literal. Which regex literal correctly matches this requirement?
A/\b[a]\w*/i
B/\b[A]\w*/
C/\b[a]\w*/
D/\b[a-z]\w*/i
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    We want words starting with 'a' or 'A'. Using case-insensitive flag i simplifies matching both.
  2. Step 2: Analyze options

    /\b[a]\w*/i uses /\b[a]\w*/i which matches word boundary, then 'a' (case-insensitive), then zero or more word chars. This matches words starting with 'a' or 'A'.
  3. Final Answer:

    /\b[a]\w*/i -> Option A
  4. Quick Check:

    Use i flag to match both 'a' and 'A' easily [OK]
Quick Trick: Use /pattern/i to match letters ignoring case [OK]
Common Mistakes:
  • Listing both 'a' and 'A' inside brackets without i flag
  • Using wrong character classes
  • Missing word boundary \b

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes