Challenge - 5 Problems
Regex Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell regex match?
Consider the following PowerShell command that uses regex anchors and quantifiers. What will be the output?
PowerShell
$text = 'abc123xyz' if ($text -match '^abc\d{3}xyz$') { 'Match' } else { 'No Match' }
Attempts:
2 left
💡 Hint
The regex checks if the entire string matches the pattern from start (^) to end ($).
✗ Incorrect
The regex ^abc\d{3}xyz$ means the string must start with 'abc', followed by exactly 3 digits, then 'xyz' and nothing else. The string 'abc123xyz' matches this exactly, so output is 'Match'.
💻 Command Output
intermediate2:00remaining
What does this regex extract from the string?
Given this PowerShell command, what will be the output?
PowerShell
$text = 'Error: 404 Not Found' if ($text -match 'Error: (\d{3})') { $matches[1] } else { 'No match' }
Attempts:
2 left
💡 Hint
The regex captures exactly three digits after 'Error: '.
✗ Incorrect
The regex 'Error: (\d{3})' matches 'Error: ' followed by exactly 3 digits. The digits are captured in group 1, so $matches[1] returns '404'.
💻 Command Output
advanced2:00remaining
What is the output of this regex with greedy quantifier?
What will this PowerShell command output?
PowerShell
$text = 'abc123xyz456' if ($text -match 'abc.*xyz') { $matches[0] } else { 'No match' }
Attempts:
2 left
💡 Hint
The .* is greedy and matches as many characters as possible but stops at the last 'xyz'.
✗ Incorrect
The regex 'abc.*xyz' matches 'abc' followed by any characters (.*) greedily until the last 'xyz'. It matches 'abc123xyz' because 'xyz456' does not match the pattern fully. So output is 'abc123xyz'.
💻 Command Output
advanced2:00remaining
What error does this regex cause in PowerShell?
What error will this command produce?
PowerShell
$text = 'abc123' if ($text -match '[a-z{3}') { 'Match' } else { 'No Match' }
Attempts:
2 left
💡 Hint
Check if the regex pattern is valid with balanced brackets.
✗ Incorrect
The regex pattern '[a-z{3}' is invalid because the character class is not closed with a ']'. This causes a syntax error in regex parsing.
💻 Command Output
expert3:00remaining
What is the output of this complex regex with anchors and quantifiers?
Analyze this PowerShell command and determine its output.
PowerShell
$text = 'start123end' if ($text -match '^(start)(\d+)(end)$') { "$($matches[1])-$($matches[2])-$($matches[3])" } else { 'No match' }
Attempts:
2 left
💡 Hint
The regex uses anchors to match the whole string and captures three groups.
✗ Incorrect
The regex ^(start)(\d+)(end)$ matches the entire string starting with 'start', then one or more digits, then 'end'. It captures these three parts in groups 1, 2, and 3. The output joins them with dashes: 'start-123-end'.