Bird
0
0

What is the output of this PowerShell code?

medium📝 Command Output Q7 of 15
PowerShell - Regular Expressions
What is the output of this PowerShell code?
$text = 'abc123'
if ($text -match 123) { 'Match' }
ANo
BFalse
CTrue
DMatch
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the -match operation

    PowerShell converts the number 123 to the string pattern '123'.
  2. Step 2: Check if 'abc123' matches '123'

    The string contains '123', so -match returns True.
  3. Step 3: Execute the if condition

    True condition enters the if block and outputs 'Match'.
  4. Final Answer:

    Match -> Option D
  5. Quick Check:

    'abc123' -match 123 = True -> Match [OK]
Quick Trick: Numbers auto-convert to string patterns in -match [OK]
Common Mistakes:
  • Expecting an error with unquoted number
  • Thinking output is boolean True
  • Believing pattern must be quoted

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes