Bird
0
0

What will be the output of this PowerShell command?

medium📝 Command Output Q4 of 15
PowerShell - Regular Expressions
What will be the output of this PowerShell command?
$text = 'hello123';
$text -match '^hello\d{3}$'
ANull
Bfalse
CError
Dtrue
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the regex pattern

    ^hello\d{3}$ matches strings starting with 'hello' followed by exactly 3 digits and nothing else.
  2. Step 2: Check the input string

    'hello123' starts with 'hello' and ends with '123' which is 3 digits, so it matches.
  3. Final Answer:

    true -> Option D
  4. Quick Check:

    Pattern matches entire string = true [OK]
Quick Trick: ^ and $ anchor full string match [OK]
Common Mistakes:
  • Ignoring anchors causing partial match confusion
  • Miscounting digits in \d{3}
  • Expecting false due to misunderstanding quantifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes