Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - String Operations
What will be the output of this PowerShell code?
$log = 'Status: 500 Internal Server Error'
if ($log -match '\d{3}') { $Matches[0] } else { 'No digits found' }
ANo digits found
B500
CStatus
DInternal
Step-by-Step Solution
Solution:
  1. Step 1: Understand the regex

    The pattern \d{3} matches exactly three consecutive digits.
  2. Step 2: Analyze the string

    The string contains '500' which matches the pattern.
  3. Step 3: Check the output

    Since the match is found, $Matches[0] contains the matched substring '500'.
  4. Final Answer:

    500 -> Option B
  5. Quick Check:

    Verify if $Matches[0] holds the first matched digits [OK]
Quick Trick: First match stored in $Matches[0] [OK]
Common Mistakes:
  • Expecting the entire string as output
  • Confusing $Matches with $match
  • Assuming no match if digits are part of a larger string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes