0
0
PowerShellscripting~10 mins

Switch with wildcard and regex 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 match the input using a wildcard pattern in the switch statement.

PowerShell
switch -Wildcard ($input) {
    [1] { Write-Output "Matched wildcard pattern" }
    default { Write-Output "No match" }
}
Drag options to blanks, or click blank then click option'
A"hello?"
B"^hello.*$"
C"hello*"
D"*world"
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex pattern with -Wildcard instead of a wildcard pattern.
Forgetting to put the pattern in quotes.
2fill in blank
medium

Complete the code to match the input using a regex pattern in the switch statement.

PowerShell
switch -Regex ($input) {
    [1] { Write-Output "Matched regex pattern" }
    default { Write-Output "No match" }
}
Drag options to blanks, or click blank then click option'
A"^hello.*$"
B"hello*"
C"hello?"
D"*world"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcard pattern with -Regex instead of a regex pattern.
Not anchoring the regex pattern properly.
3fill in blank
hard

Fix the error in the switch statement to correctly match input ending with 'end' using wildcard.

PowerShell
switch -Wildcard ($input) {
    [1] { Write-Output "Ends with 'end'" }
    default { Write-Output "No match" }
}
Drag options to blanks, or click blank then click option'
A"end*"
B"*end"
C"?end"
D"*en"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'end*' which matches strings starting with 'end' instead of ending.
Using '?' which matches exactly one character.
4fill in blank
hard

Fill both blanks to match input starting with 'start' using regex and containing digits.

PowerShell
switch -Regex ($input) {
    [1] { Write-Output "Starts with start" }
    [2] { Write-Output "Contains digits" }
    default { Write-Output "No match" }
}
Drag options to blanks, or click blank then click option'
A"^start"
B"\d+"
C"start$"
D"[a-z]+"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start$' which matches strings ending with 'start'.
Using '[a-z]+' which matches letters but not digits.
5fill in blank
hard

Fill all three blanks to create a switch that matches input exactly 'yes', matches input containing 'no' anywhere, and matches input starting with 'maybe' using regex.

PowerShell
switch -Regex ($input) {
    [1] { Write-Output "Exact yes" }
    [2] { Write-Output "Contains no" }
    [3] { Write-Output "Starts with maybe" }
    default { Write-Output "No match" }
}
Drag options to blanks, or click blank then click option'
A"^yes$"
B"no"
C"^maybe"
D"yes"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'yes' without anchors matches any string containing 'yes', not exactly 'yes'.
Using '^no' which matches strings starting with 'no' only.