Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to replace 'cat' with 'dog' in the string.
PowerShell
'I have a cat' [1] 'cat' 'dog'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' instead of '-replace' which only checks for a match.
Using '-like' which is for wildcard matching, not replacement.
✗ Incorrect
The '-replace' operator in PowerShell replaces text matching a pattern with a replacement string.
2fill in blank
mediumComplete the code to replace all digits with '#' in the string.
PowerShell
'Phone: 123-4567' [1] '\d' '#'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which only tests for presence of pattern, not replacement.
Using '-like' which does not support regex.
✗ Incorrect
The '-replace' operator uses regex patterns like '\d' to find digits and replace them.
3fill in blank
hardFix the error in the code to replace 'blue' with 'red' ignoring case.
PowerShell
'Blue sky' [1] '(?i)blue' 'red'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which does not replace text.
Using '-like' which does not support regex.
✗ Incorrect
The '-replace' operator supports regex with inline case-insensitive flag '(?i)'.
4fill in blank
hardFill both blanks to replace all vowels with '*' in the string.
PowerShell
'Hello World' [1] [2] '*'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' instead of '-replace' for replacement.
Using '[0-9]' which matches digits, not vowels.
✗ Incorrect
Use '-replace' with a regex pattern matching vowels to replace them with '*'.
5fill in blank
hardFill all three blanks to replace 'cat' or 'dog' with 'pet' in the string.
PowerShell
'I have a cat and a dog' [1] [2] [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which does not replace text.
Using a pattern without the '|' to match both words.
✗ Incorrect
Use '-replace' with regex 'cat|dog' to replace either word with 'pet'.