Bird
0
0

Why does Select-String with pattern '\bword\b' only match whole words and not substrings?

hard📝 Conceptual Q10 of 15
PowerShell - Regular Expressions
Why does Select-String with pattern '\bword\b' only match whole words and not substrings?
ABecause '\b' matches the start of the line only
BBecause '\b' matches word boundaries, ensuring exact word matches
CBecause '\b' matches any whitespace character
DBecause '\b' matches digits only
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of '\b' in regex

    '\b' matches a word boundary, i.e., position between word and non-word characters.
  2. Step 2: Explain effect on matching

    Using '\bword\b' matches 'word' as a whole word, not part of longer words.
  3. Final Answer:

    Because '\b' matches word boundaries, ensuring exact word matches -> Option B
  4. Quick Check:

    \b = word boundary anchor in regex [OK]
Quick Trick: Use \b to match whole words only in regex [OK]
Common Mistakes:
  • Thinking \b matches whitespace or line start
  • Confusing \b with digit matching
  • Assuming it matches substrings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes