Bird
0
0

Which variable stores the matched substring after using -match in PowerShell?

easy📝 Conceptual Q2 of 15
PowerShell - Regular Expressions
Which variable stores the matched substring after using -match in PowerShell?
A$MatchedString
B$Match
C$Matches
D$Result
Step-by-Step Solution
Solution:
  1. Step 1: Recall automatic variables in PowerShell

    PowerShell stores regex match results in a special automatic variable called $Matches.
  2. Step 2: Confirm the correct variable name

    The variable $Matches holds the matched substring after a successful -match.
  3. Final Answer:

    $Matches -> Option C
  4. Quick Check:

    Match result variable = $Matches [OK]
Quick Trick: Matched text is in $Matches automatic variable [OK]
Common Mistakes:
  • Using $Match instead of $Matches
  • Expecting match in $Result
  • Confusing with user-defined variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes