Challenge - 5 Problems
Regex Pattern Mastery
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?
Given the following PowerShell code, what is the output?
PowerShell
$text = 'cat bat rat' if ($text -match '\b[a-z]at\b') { $matches[0] } else { 'No match' }
Attempts:
2 left
💡 Hint
The -match operator returns the first match found in the string.
✗ Incorrect
The regex '\b[a-z]at\b' matches any three-letter word ending with 'at'. The first such word in the string is 'cat', so $matches[0] contains 'cat'.
🧠 Conceptual
intermediate2:00remaining
Why does regex enable flexible pattern matching?
Which statement best explains why regex is powerful for pattern matching in scripts?
Attempts:
2 left
💡 Hint
Think about how regex can match different patterns, not just fixed text.
✗ Incorrect
Regex uses special characters like '.', '*', and '\b' to create flexible patterns that can match many variations of text, making it powerful for searching and validating strings.
📝 Syntax
advanced2:00remaining
Which PowerShell regex pattern matches an email address?
Select the regex pattern that correctly matches a simple email format in PowerShell.
Attempts:
2 left
💡 Hint
Look for a pattern that allows letters, digits, dots, and hyphens before and after '@', and a domain suffix.
✗ Incorrect
Option D matches one or more word characters, dots, or hyphens before '@', then similar after '@', followed by a dot and at least two letters for domain suffix, which fits a simple email format.
🔧 Debug
advanced2:00remaining
Why does this PowerShell regex fail to match?
Given this code, why does it not match the word 'hello'?
$text = 'hello world'
if ($text -match '[h-e]+') { 'Match found' } else { 'No match' }
Attempts:
2 left
💡 Hint
Check the order of characters inside the square brackets for ranges.
✗ Incorrect
Character ranges in regex must be from lower to higher character code. '[h-e]' is invalid because 'h' has a higher code than 'e', so the pattern fails to compile and match.
🚀 Application
expert2:00remaining
How many matches does this PowerShell regex find?
Count how many matches this regex finds in the string:
$text = 'one1 two2 three3 four4'
$matches = [regex]::Matches($text, '\b\w+\d\b')
$matches.Count
Attempts:
2 left
💡 Hint
Look for words ending with a digit, separated by word boundaries.
✗ Incorrect
The regex '\b\w+\d\b' matches words that end with a digit. The string has 'one1', 'two2', 'three3', and 'four4', so 4 matches are found.