0
0
PowerShellscripting~5 mins

Regular expressions with -match in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -match operator do in PowerShell?
It checks if a string matches a pattern defined by a regular expression and returns True or False.
Click to reveal answer
beginner
How do you capture the matched text when using -match?
PowerShell stores the matched text in the automatic variable $Matches.
Click to reveal answer
beginner
What will this command output?<br>
$text = 'Hello123'; $text -match '\d+'
It will output True because \d+ matches one or more digits in the string.
Click to reveal answer
beginner
How can you check if a string does NOT match a regex pattern in PowerShell?
Use the -notmatch operator, which returns True if the string does NOT match the pattern.
Click to reveal answer
beginner
What type of value does -match return?
It returns a Boolean value: True if the pattern matches, otherwise False.
Click to reveal answer
What does $string -match 'abc' return if $string contains 'xyzabc123'?
ANull
BFalse
CAn error
DTrue
Where does PowerShell store the matched text after using -match?
A$MatchText
B$MatchedString
C$Matches
D$Match
What will 'PowerShell' -match '^Power' return?
ATrue
BNull
CAn error
DFalse
Which operator checks if a string does NOT match a regex pattern?
A-notmatch
B-match
C-contains
D-like
What type of pattern does -match use?
AWildcard pattern
BRegular expression
CExact string match
DJSON pattern
Explain how to use the -match operator in PowerShell to find if a string contains digits.
Think about how to write a regex for digits and how to check the result.
You got /4 concepts.
    Describe the difference between -match and -notmatch in PowerShell.
    Consider what happens when the pattern is found or not found.
    You got /3 concepts.