Bird
0
0

What does a capture group do in a Ruby regular expression like /(\d{3})-(\d{2})/?

easy📝 Conceptual Q11 of 15
Ruby - Regular Expressions
What does a capture group do in a Ruby regular expression like /(\d{3})-(\d{2})/?
AIt repeats the pattern multiple times.
BIt saves parts of the matched text for later use.
CIt matches only digits without saving.
DIt ignores the matched text.
Step-by-Step Solution
Solution:
  1. Step 1: Understand capture groups in regex

    Capture groups are parts of a pattern enclosed in parentheses that save matched text.
  2. Step 2: Analyze the example pattern

    The pattern /(\d{3})-(\d{2})/ has two capture groups for three digits and two digits separated by a dash.
  3. Final Answer:

    It saves parts of the matched text for later use. -> Option B
  4. Quick Check:

    Capture groups = save matched parts [OK]
Quick Trick: Parentheses in regex save matched text as groups [OK]
Common Mistakes:
  • Thinking capture groups repeat patterns
  • Confusing capture groups with non-capturing groups
  • Believing capture groups ignore matched text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes