0
0
PowerShellscripting~20 mins

Regex quantifiers and anchors in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regex Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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' }
AFalse
BNo Match
CSyntaxError
DMatch
Attempts:
2 left
💡 Hint
The regex checks if the entire string matches the pattern from start (^) to end ($).
💻 Command Output
intermediate
2: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' }
A404
BError
CNo match
DSyntaxError
Attempts:
2 left
💡 Hint
The regex captures exactly three digits after 'Error: '.
💻 Command Output
advanced
2: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' }
Aabc123xyz
Babc123xyz456
CNo match
DSyntaxError
Attempts:
2 left
💡 Hint
The .* is greedy and matches as many characters as possible but stops at the last 'xyz'.
💻 Command Output
advanced
2: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' }
ANo Match
BMatch
CSyntaxError
DRuntimeException
Attempts:
2 left
💡 Hint
Check if the regex pattern is valid with balanced brackets.
💻 Command Output
expert
3: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' }
ANo match
Bstart-123-end
Cstart123end
DSyntaxError
Attempts:
2 left
💡 Hint
The regex uses anchors to match the whole string and captures three groups.