Bird
0
0

What will be the output of this command?

medium📝 Command Output Q5 of 15
PowerShell - Regular Expressions
What will be the output of this command?
"apple`nbanana`napple" | Select-String -Pattern '^apple$'
AMatches any line containing 'apple', so lines 1 and 3
BMatches only the first line
CNo matches because pattern is incorrect
DMatches lines exactly equal to 'apple', so lines 1 and 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand '^apple$' matches lines exactly 'apple'

    ^ and $ anchor start and end of line, so only lines exactly 'apple' match.
  2. Step 2: Analyze input lines

    Lines 1 and 3 are 'apple', line 2 is 'banana'. So lines 1 and 3 match.
  3. Final Answer:

    Matches lines exactly equal to 'apple', so lines 1 and 3 -> Option D
  4. Quick Check:

    Use ^ and $ to match whole line exactly [OK]
Quick Trick: Use ^ and $ to match whole line exactly in regex [OK]
Common Mistakes:
  • Thinking it matches partial lines
  • Assuming only first line matches
  • Believing pattern is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes