Bird
0
0

Which of the following PowerShell commands correctly checks if the variable $input contains any numeric digits using -match?

easy📝 Syntax Q3 of 15
PowerShell - String Operations
Which of the following PowerShell commands correctly checks if the variable $input contains any numeric digits using -match?
Aif ($input -match '\d') { 'Digits found' }
Bif ($input -match '[0-9]+') { 'Digits found' }
Cif ($input -match '[a-z]') { 'Digits found' }
Dif ($input -match '\w+') { 'Digits found' }
Step-by-Step Solution
Solution:
  1. Step 1: Identify regex for digits

    The regex \d matches any single digit character.
  2. Step 2: Analyze options

    if ($input -match '\d') { 'Digits found' } uses \d correctly. if ($input -match '[0-9]+') { 'Digits found' } uses [0-9]+ which also matches digits but the question asks for any digits, so \d is simpler and correct. if ($input -match '[a-z]') { 'Digits found' } matches letters, not digits. if ($input -match '\w+') { 'Digits found' } matches word characters including letters and digits, so it is not specific.
  3. Final Answer:

    if ($input -match '\d') { 'Digits found' } -> Option A
  4. Quick Check:

    Check if regex matches digits only [OK]
Quick Trick: Use \d to match digits in regex [OK]
Common Mistakes:
  • Using character classes that include letters instead of digits
  • Confusing \w (word chars) with digits
  • Using incorrect regex syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes