Bird
0
0

Why does the -match operator return False when matching an empty string pattern?

hard📝 Conceptual Q10 of 15
PowerShell - Regular Expressions
Why does the -match operator return False when matching an empty string pattern?
AEmpty pattern matches everywhere, but -match treats it as no match
BEmpty pattern matches only empty strings, so no match in non-empty text
CPowerShell ignores empty patterns silently
DEmpty pattern is invalid and causes an error
Step-by-Step Solution
Solution:
  1. Step 1: Understand regex empty string pattern

    An empty regex pattern matches only empty strings, not non-empty text.
  2. Step 2: Apply to -match operator behavior

    When matching a non-empty string with an empty pattern, -match returns False.
  3. Final Answer:

    Empty pattern matches only empty strings, so no match in non-empty text -> Option B
  4. Quick Check:

    Empty pattern matches empty strings only [OK]
Quick Trick: Empty pattern matches only empty strings, not text [OK]
Common Mistakes:
  • Expecting empty pattern to match all text
  • Thinking empty pattern causes error
  • Assuming PowerShell ignores empty patterns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes