0
0
PowerShellscripting~20 mins

String comparison (-like, -match) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider the following command:
$result = 'HelloWorld' -like 'Hello*'
What is the value of $result?
PowerShell
$result = 'HelloWorld' -like 'Hello*'
Write-Output $result
ATrue
BFalse
CHelloWorld
DError
Attempts:
2 left
💡 Hint
The -like operator uses wildcard matching with * as any characters.
💻 Command Output
intermediate
2:00remaining
What does this PowerShell command output?
Given the command:
$result = 'PowerShell123' -match '\d{3}'
What is the value of $result?
PowerShell
$result = 'PowerShell123' -match '\d{3}'
Write-Output $result
AFalse
B123
CTrue
DError
Attempts:
2 left
💡 Hint
The -match operator returns True if the regex pattern matches anywhere in the string.
📝 Syntax
advanced
2:00remaining
Which option correctly uses -like to check if a string ends with '.txt'?
You want to check if the variable $fileName ends with '.txt' using the -like operator. Which of these is correct?
A$fileName -like 'txt*.'
B$fileName -like '.txt*'
C$fileName -like '*txt.'
D$fileName -like '*.txt'
Attempts:
2 left
💡 Hint
The * wildcard matches any characters before '.txt' at the end.
💻 Command Output
advanced
2:00remaining
What is the output of this PowerShell snippet?
Analyze the code:
$text = 'Data123'
if ($text -match '^Data\d+$') { 'Match' } else { 'No Match' }
What will it output?
PowerShell
$text = 'Data123'
if ($text -match '^Data\d+$') { 'Match' } else { 'No Match' }
ANo Match
BMatch
CError
DData123
Attempts:
2 left
💡 Hint
The regex ^Data\d+$ means string starts with 'Data' followed by one or more digits till end.
🧠 Conceptual
expert
2:00remaining
Which statement about -like and -match is TRUE in PowerShell?
Choose the correct statement about the difference between -like and -match operators.
A-like uses wildcard patterns and is case-insensitive by default; -match uses regular expressions and is case-insensitive by default.
B-like uses regular expressions and is case-sensitive; -match uses wildcard patterns and is case-insensitive.
C-like and -match both use regular expressions but differ in case sensitivity.
D-like uses wildcard patterns and is case-sensitive; -match uses regular expressions and is case-sensitive.
Attempts:
2 left
💡 Hint
Think about pattern types and default case sensitivity.