Challenge - 5 Problems
Regex PowerShell Master
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 string
'Contact: user@example.com', what will be the output of this command?$string = 'Contact: user@example.com'
if ($string -match '\b\w+@\w+\.\w+\b') { $matches[0] }PowerShell
$string = 'Contact: user@example.com' if ($string -match '\b\w+@\w+\.\w+\b') { $matches[0] }
Attempts:
2 left
💡 Hint
Look for the pattern that matches an email format.
✗ Incorrect
The regex matches a simple email pattern. The matched substring is 'user@example.com'.
💻 Command Output
intermediate2:00remaining
What does this regex extract from the date string?
Given the string
'Date: 2024-06-15', what will this command output?$date = 'Date: 2024-06-15'
if ($date -match '(\d{4})-(\d{2})-(\d{2})') { "$($matches[1])/$($matches[2])/$($matches[3])" }PowerShell
$date = 'Date: 2024-06-15' if ($date -match '(\d{4})-(\d{2})-(\d{2})') { "$($matches[1])/$($matches[2])/$($matches[3])" }
Attempts:
2 left
💡 Hint
The regex captures year, month, and day in groups.
✗ Incorrect
The regex captures the year, month, and day parts separately and outputs them in YYYY/MM/DD format.
📝 Syntax
advanced2:00remaining
Which regex pattern matches a US phone number format?
Which option correctly matches a US phone number like (123) 456-7890 in PowerShell regex?
Attempts:
2 left
💡 Hint
Look for the pattern with parentheses, space, and dash in correct places.
✗ Incorrect
Option B matches the exact format with parentheses around area code, a space, then three digits, a dash, and four digits.
🔧 Debug
advanced2:00remaining
Why does this regex fail to match an IP address?
This PowerShell code tries to match an IP address but fails:
Why does it fail?
$ip = '192.168.1.1'
if ($ip -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') { 'Match' } else { 'No match' }Why does it fail?
Attempts:
2 left
💡 Hint
Check how backslashes are handled in PowerShell strings.
✗ Incorrect
In PowerShell, backslashes must be escaped in double-quoted strings or use single quotes. Here, the pattern uses single quotes but the backslash before dot is not doubled, so it is treated literally.
🚀 Application
expert3:00remaining
Extract all hashtags from a tweet using PowerShell regex
You have this tweet string:
Which PowerShell command extracts all hashtags as an array?
$tweet = 'Learning #PowerShell and #regex is fun! #automation'Which PowerShell command extracts all hashtags as an array?
Attempts:
2 left
💡 Hint
Look for a method to iterate over matches and extract their values.
✗ Incorrect
Option A uses ForEach to iterate over the MatchCollection and extract the Value property of each match, returning an array of hashtags.