Bird
0
0

What will this PowerShell command output?

medium📝 Command Output Q5 of 15
PowerShell - Regular Expressions
What will this PowerShell command output?
$text = 'hello world'; $text -replace '\\bworld\\b', 'PowerShell'
APowerShell world
Bhello world
Chello PowerShell
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the regex pattern \\bworld\\b

    \\b matches word boundaries, so it matches 'world' as a whole word.
  2. Step 2: Replace 'world' with 'PowerShell'

    The command replaces 'world' with 'PowerShell' in the string.
  3. Final Answer:

    The output is 'hello PowerShell' -> Option C
  4. Quick Check:

    Word boundary replace works = 'hello PowerShell' [OK]
Quick Trick: Use \\b to match whole words only [OK]
Common Mistakes:
  • Not using word boundaries and replacing partial matches
  • Expecting original string unchanged
  • Confusing -replace with -match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes