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'?✗ Incorrect
The string contains 'abc', so
-match returns True.Where does PowerShell store the matched text after using
-match?✗ Incorrect
PowerShell stores matched groups in the automatic variable
$Matches.What will
'PowerShell' -match '^Power' return?✗ Incorrect
The pattern '^Power' matches the start of the string 'PowerShell', so it returns
True.Which operator checks if a string does NOT match a regex pattern?
✗ Incorrect
-notmatch returns True if the string does NOT match the regex.What type of pattern does
-match use?✗ Incorrect
-match uses regular expressions to find patterns in strings.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.