Bird
0
0

Which command correctly replaces all digits in the string 'user456' with the character '*' using -replace?

easy📝 Syntax Q3 of 15
PowerShell - Regular Expressions
Which command correctly replaces all digits in the string 'user456' with the character '*' using -replace?
A'user456' -replace '[a-z]', '*'
B'user456' -replace '\d', '*'
C'user456' -replace '\D', '*'
D'user456' -replace '*', '\d'
Step-by-Step Solution
Solution:
  1. Step 1: Identify pattern for digits

    The regex pattern \d matches digits.
  2. Step 2: Check replacement

    Replacing digits with '*' is done by -replace '\d', '*'.
  3. Step 3: Validate other options

    'user456' -replace '[a-z]', '*' replaces letters, C replaces non-digits, D has invalid syntax.
  4. Final Answer:

    'user456' -replace '\d', '*' -> Option B
  5. Quick Check:

    Does the pattern match digits? [OK]
Quick Trick: Use '\d' to match digits in -replace [OK]
Common Mistakes:
  • Using '\D' instead of '\d'
  • Replacing letters instead of digits
  • Incorrect syntax for replacement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes