0
0
PowerShellscripting~20 mins

Why regex enables pattern matching in PowerShell - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regex Pattern Mastery
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?
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' }
Acat
Bbat
Crat
DNo match
Attempts:
2 left
💡 Hint
The -match operator returns the first match found in the string.
🧠 Conceptual
intermediate
2:00remaining
Why does regex enable flexible pattern matching?
Which statement best explains why regex is powerful for pattern matching in scripts?
ARegex uses special symbols to define complex search patterns.
BRegex can only match numbers and letters but not symbols.
CRegex allows matching exact strings only without variations.
DRegex requires manual checking of each character in a string.
Attempts:
2 left
💡 Hint
Think about how regex can match different patterns, not just fixed text.
📝 Syntax
advanced
2:00remaining
Which PowerShell regex pattern matches an email address?
Select the regex pattern that correctly matches a simple email format in PowerShell.
A'[a-z]+@[0-9]+\.[a-z]{2}'
B'[a-zA-Z]+\s@[a-zA-Z]+\.[a-z]{3}'
C'^\d+@\w+\.com$'
D'^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$'
Attempts:
2 left
💡 Hint
Look for a pattern that allows letters, digits, dots, and hyphens before and after '@', and a domain suffix.
🔧 Debug
advanced
2: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' }
AThe regex should use double quotes instead of single quotes.
BThe regex is missing anchors ^ and $ to match the whole word.
CThe character range [h-e] is invalid because 'h' comes after 'e'.
DPowerShell -match operator does not support character ranges.
Attempts:
2 left
💡 Hint
Check the order of characters inside the square brackets for ranges.
🚀 Application
expert
2: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
A3
B4
C2
D1
Attempts:
2 left
💡 Hint
Look for words ending with a digit, separated by word boundaries.