Bird
0
0

Which of the following is the correct PowerShell syntax to check if the string 'Hello123' contains digits using regex?

easy📝 Syntax Q12 of 15
PowerShell - Regular Expressions
Which of the following is the correct PowerShell syntax to check if the string 'Hello123' contains digits using regex?
A'Hello123' -contains '\d+'
B'Hello123' -match '[a-z]+'
C'Hello123' -match '\d+'
D'Hello123' -like '*\d+'
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct operator and pattern

    PowerShell uses '-match' to test regex patterns. '\d+' matches one or more digits.
  2. Step 2: Check options

    'Hello123' -match '\d+' uses '-match' with '\d+' correctly. Others use wrong operators or patterns.
  3. Final Answer:

    'Hello123' -match '\d+' -> Option C
  4. Quick Check:

    Use '-match' with '\d+' for digits [OK]
Quick Trick: Use '-match' with '\d+' to find digits [OK]
Common Mistakes:
  • Using '-contains' instead of '-match'
  • Using '-like' with regex patterns
  • Forgetting to escape backslash in regex

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes