Bird
0
0

What is the purpose of capture groups in Ruby regular expressions?

easy📝 Conceptual Q1 of 15
Ruby - Regular Expressions
What is the purpose of capture groups in Ruby regular expressions?
ATo repeat a pattern multiple times
BTo extract specific parts of a matched string
CTo ignore case sensitivity in matching
DTo match only the start of a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand capture groups

    Capture groups are parts of a regex enclosed in parentheses that save matched text.
  2. Step 2: Identify their purpose

    They allow extracting or referencing specific parts of the matched string.
  3. Final Answer:

    To extract specific parts of a matched string -> Option B
  4. Quick Check:

    Capture groups = extract parts [OK]
Quick Trick: Parentheses in regex save matched text for reuse [OK]
Common Mistakes:
  • Confusing capture groups with non-capturing groups
  • Thinking capture groups repeat patterns
  • Assuming capture groups change case sensitivity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes