Bird
0
0

Which of the following is the correct Ruby syntax to match any word character one or more times?

easy📝 Syntax Q12 of 15
Ruby - Regular Expressions
Which of the following is the correct Ruby syntax to match any word character one or more times?
A/\w+/
B/\w*/
C/\w?/
D/\w{}/
Step-by-Step Solution
Solution:
  1. Step 1: Understand quantifiers in regex

    + means one or more times, * means zero or more, ? means zero or one.
  2. Step 2: Apply to \w

    /\w+/ matches one or more word characters, which is the correct syntax.
  3. Final Answer:

    /\w+/ -> Option A
  4. Quick Check:

    One or more word chars = /\w+/ [OK]
Quick Trick: Use + for one or more matches in regex [OK]
Common Mistakes:
  • Using * which allows zero matches
  • Using ? which allows zero or one match
  • Using empty braces {} which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes