Bird
0
0

You run Select-String -Pattern "[0-9]+" -Path "file.txt" but get no output, even though 'file.txt' contains numbers. What is the likely problem?

medium📝 Debug Q14 of 15
PowerShell - Regular Expressions
You run Select-String -Pattern "[0-9]+" -Path "file.txt" but get no output, even though 'file.txt' contains numbers. What is the likely problem?
AThe regex pattern is incorrect for matching numbers.
BThe file path is wrong or file does not exist.
CSelect-String does not support regex patterns.
DThe command needs -AllMatches to find numbers.
Step-by-Step Solution
Solution:
  1. Step 1: Check regex pattern validity

    The pattern "[0-9]+" correctly matches one or more digits.
  2. Step 2: Consider file path and existence

    If no output, likely the file path is incorrect or the file does not exist, so no lines are searched.
  3. Final Answer:

    The file path is wrong or file does not exist. -> Option B
  4. Quick Check:

    Valid regex but no output means file issue [OK]
Quick Trick: Check file path and existence if no matches found [OK]
Common Mistakes:
  • Assuming regex is wrong when it's correct
  • Thinking Select-String can't use regex
  • Believing -AllMatches is required for any match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes