Bird
0
0

What does a named capture group do in a PowerShell regex pattern like (?\d{4})?

easy📝 Conceptual Q11 of 15
PowerShell - Regular Expressions
What does a named capture group do in a PowerShell regex pattern like (?\d{4})?
AMatches only the first 4 characters of the string
BMakes the regex case-insensitive
CRepeats the pattern 4 times
DLabels the matched part as 'year' for easy access later
Step-by-Step Solution
Solution:
  1. Step 1: Understand named capture syntax

    The syntax (?pattern) labels the matched text as 'name'.
  2. Step 2: Identify the purpose in the example

    Here, (?\d{4}) captures 4 digits and labels them 'year'.
  3. Final Answer:

    Labels the matched part as 'year' for easy access later -> Option D
  4. Quick Check:

    Named capture = label matched text [OK]
Quick Trick: Look for (?pattern) to label matches [OK]
Common Mistakes:
  • Thinking it changes match behavior
  • Confusing with quantifiers
  • Assuming it matches only start of string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes