Bird
0
0

Why does -match only return the first match in PowerShell, unlike some other languages?

hard📝 Conceptual Q10 of 15
PowerShell - String Operations
Why does -match only return the first match in PowerShell, unlike some other languages?
ABecause it returns all matches but only shows the first
BBecause PowerShell does not support regex fully
CBecause it requires a special flag to return all matches
DBecause -match is designed to return a boolean and first match only
Step-by-Step Solution
Solution:
  1. Step 1: Understand -match design

    -match is a boolean operator that tests if a pattern exists.
  2. Step 2: Recognize match storage

    It stores only the first match in $Matches, not all matches.
  3. Final Answer:

    Because -match is designed to return a boolean and first match only -> Option D
  4. Quick Check:

    -match returns True and first match only [OK]
Quick Trick: -match returns True and first match only [OK]
Common Mistakes:
  • Thinking PowerShell lacks regex support
  • Expecting all matches without extra methods
  • Assuming -match returns all matches silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes