Bird
0
0

Which of the following is the correct way to access a named capture group 'year' after a successful match in PowerShell?

easy📝 Syntax Q3 of 15
PowerShell - Regular Expressions
Which of the following is the correct way to access a named capture group 'year' after a successful match in PowerShell?
A$matches{year}
B$matches['year']
C$matches(year)
D$matches.year
Step-by-Step Solution
Solution:
  1. Step 1: Understand $matches variable

    After -match, $matches is a hashtable where keys are group names as strings.
  2. Step 2: Access named group

    Use $matches['year'] to get the value of the named group 'year'.
  3. Final Answer:

    $matches['year'] -> Option B
  4. Quick Check:

    Access named group = $matches['name'] [OK]
Quick Trick: Use square brackets with quotes to access named groups [OK]
Common Mistakes:
  • Using dot notation which doesn't work on $matches
  • Using parentheses or curly braces incorrectly
  • Forgetting quotes around the group name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes