0
0
PowerShellscripting~5 mins

match operator in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PowerShell match operator (-match) do?
The -match operator checks if a string contains a pattern using regular expressions. It returns True if the pattern is found, otherwise False.
Click to reveal answer
beginner
How do you use the match operator to find if 'apple' is in the string 'I like apples'?
You write: 'I like apples' -match 'apple'. This returns True because 'apple' is part of 'apples'.
Click to reveal answer
beginner
What type of pattern does the match operator use?
It uses regular expressions (regex), which are special patterns to find text in strings.
Click to reveal answer
intermediate
What is stored in the automatic variable $matches after a successful -match operation?
$matches is a hashtable that stores the matched text and any captured groups from the regex pattern.
Click to reveal answer
intermediate
How can you perform a case-insensitive match with the match operator?
By default, -match is case-insensitive. To make it case-sensitive, use -cmatch instead.
Click to reveal answer
What does the PowerShell -match operator return when the pattern is found in the string?
ATrue
BFalse
CThe matched string
DAn error
Which variable holds the matched text after using -match?
A$match
B$matches
C$matchedText
D$result
How do you write a case-sensitive match in PowerShell?
A-match
B-imatch
C-cmatch
D-smatch
What kind of patterns does -match use to find text?
ASimple text only
BJSON paths
CXML patterns
DRegular expressions
What will 'Hello World' -match 'world' return?
ATrue
BFalse
CError
DNull
Explain how the PowerShell match operator works and what $matches contains after a match.
Think about searching text and what info you want after a match.
You got /3 concepts.
    Describe how to perform case-sensitive and case-insensitive matches using PowerShell operators.
    Remember the 'c' in -cmatch stands for case-sensitive.
    You got /2 concepts.