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?
✗ Incorrect
-like uses wildcards like * and ? for simple pattern matching.What does the
-match operator use to compare strings?✗ Incorrect
-match uses regular expressions for flexible pattern matching.What will
'PowerShell' -like 'P*Shell' return?✗ Incorrect
The pattern matches because it starts with 'P' and ends with 'Shell'.
Which variable holds captured groups after a successful
-match operation?✗ Incorrect
Captured groups are stored in the automatic variable
$matches.Which operator would you use to check if a string exactly equals another string?
✗ Incorrect
-eq checks for exact equality, not pattern matching.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.