Bird
0
0

Which PowerShell command correctly checks if the variable $inputString contains any numeric characters using regex?

easy📝 Syntax Q3 of 15
PowerShell - Regular Expressions
Which PowerShell command correctly checks if the variable $inputString contains any numeric characters using regex?
ATest-Path $inputString '\d+'
B$inputString -contains '\d+'
CSelect-String $inputString '\d+'
D$inputString -match '\d+'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the operator

    The '-match' operator in PowerShell is used to test if a string matches a regex pattern.
  2. Step 2: Identify the correct regex pattern

    '\d+' matches one or more digits.
  3. Final Answer:

    $inputString -match '\d+' -> Option D
  4. Quick Check:

    Using '-contains' or 'Test-Path' does not perform regex matching [OK]
Quick Trick: Use '-match' for regex pattern matching in strings [OK]
Common Mistakes:
  • Using '-contains' instead of '-match' for regex
  • Confusing cmdlets like Select-String for simple matching
  • Using Test-Path which is for filesystem paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes