Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the string contains the word 'cat'.
PowerShell
$text = 'The cat is sleeping.' if ($text [1] 'cat') { Write-Output 'Found a cat!' }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-contains' which is for collections, not strings.
Using '-eq' which checks for exact equality.
✗ Incorrect
The '-match' operator checks if the string matches the regular expression pattern.
2fill in blank
mediumComplete the code to check if the string starts with a digit using a regular expression.
PowerShell
$text = '3 cats' if ($text [1] '^[0-9]') { Write-Output 'Starts with a digit' }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-like' which does not support full regex.
Using '-contains' which is for collections.
✗ Incorrect
The '-match' operator supports regex patterns like '^[0-9]' to check the start of the string.
3fill in blank
hardFix the error in the code to check if the string ends with '.txt'.
PowerShell
$filename = 'document.txt' if ($filename [1] '\.txt$') { Write-Output 'Text file detected' }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-like' which does not support regex anchors like '$'.
Using '-eq' which checks exact equality.
✗ Incorrect
The '-match' operator is needed to use regex patterns like '\.txt$' to check the string ending.
4fill in blank
hardFill both blanks to create a regex that matches strings with exactly 3 digits.
PowerShell
$input = '123' if ($input [1] '^[0-9][2]$') { Write-Output 'Exactly three digits' }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-like' which does not support regex quantifiers.
Using '{2}' which matches exactly two digits.
✗ Incorrect
Use '-match' for regex matching and '{3}' to specify exactly three digits.
5fill in blank
hardFill all three blanks to create a regex that matches strings starting with 'a' or 'b' followed by one or more digits.
PowerShell
$text = 'a123' if ($text [1] '^[[2]][0-9][3]$') { Write-Output 'Match found' }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which means zero or more, not one or more.
Using '-like' which does not support regex.
✗ Incorrect
Use '-match' for regex, '[ab]' to match 'a' or 'b', and '+' to match one or more digits.