0
0
PowerShellscripting~5 mins

String comparison (-like, -match) in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PowerShell operator -like do?
The -like operator checks if a string matches a pattern using wildcard characters like * and ?. It returns True if the pattern matches part or all of the string.
Click to reveal answer
intermediate
How does the -match operator differ from -like in PowerShell?
-match uses regular expressions to compare strings, allowing more complex pattern matching than -like, which uses simple wildcards.
Click to reveal answer
beginner
Example: What is the result of 'hello' -like 'h*o'?
It returns True because the pattern h*o matches any string starting with 'h' and ending with 'o', including 'hello'.
Click to reveal answer
intermediate
Example: What does 'hello' -match '^h.*o$' return?
It returns True because the regular expression ^h.*o$ means the string starts with 'h' and ends with 'o', matching 'hello'.
Click to reveal answer
advanced
Can -match capture parts of a string? How?
Yes, -match can capture parts using parentheses in the regex. Captured groups are stored in the automatic variable $matches.
Click to reveal answer
Which operator uses wildcard characters like * and ? for string comparison in PowerShell?
A-match
B-contains
C-eq
D-like
What does the -match operator use to compare strings?
ARegular expressions
BExact equality
CWildcards
DNumeric comparison
What will 'PowerShell' -like 'P*Shell' return?
AFalse
BTrue
CError
DNull
Which variable holds captured groups after a successful -match operation?
A$matches
B$groups
C$result
D$capture
Which operator would you use to check if a string exactly equals another string?
A-like
B-match
C-eq
D-contains
Explain the difference between the PowerShell operators -like and -match.
Think about simple vs complex pattern matching.
You got /4 concepts.
    Describe how to capture parts of a string using the -match operator in PowerShell.
    Remember $matches is automatic after -match.
    You got /3 concepts.