0
0
PowerShellscripting~10 mins

-replace operator in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A-match
B-replace
C-like
D-contains
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.
2fill in blank
medium

Complete 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'
A-like
B-match
C-contains
D-replace
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which only tests for presence of pattern, not replacement.
Using '-like' which does not support regex.
3fill in blank
hard

Fix 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'
A-contains
B-match
C-replace
D-like
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which does not replace text.
Using '-like' which does not support regex.
4fill in blank
hard

Fill 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'
A-replace
B[aeiouAEIOU]
C[0-9]
D-match
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' instead of '-replace' for replacement.
Using '[0-9]' which matches digits, not vowels.
5fill in blank
hard

Fill 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'
A-replace
B'cat|dog'
C'pet'
D-match
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-match' which does not replace text.
Using a pattern without the '|' to match both words.