0
0
PowerShellscripting~20 mins

Regex with Select-String in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regex Master with Select-String
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Select-String with simple regex
What is the output of this PowerShell command when run on a file containing the lines:
apple
banana
apricot
grape

Command:
Select-String -Pattern '^a' -Path 'fruits.txt'
PowerShell
Select-String -Pattern '^a' -Path 'fruits.txt'
Aapple<br>banana<br>apricot<br>grape
Bbanana<br>grape
Capple<br>apricot
DNo output
Attempts:
2 left
💡 Hint
The regex '^a' matches lines starting with 'a'.
💻 Command Output
intermediate
2:00remaining
Select-String with case-insensitive regex
Given a file 'colors.txt' with lines:
Red
blue
GREEN
Yellow

What is the output of:
Select-String -Pattern 'green' -Path 'colors.txt' -CaseSensitive:$false
PowerShell
Select-String -Pattern 'green' -Path 'colors.txt' -CaseSensitive:$false
AGREEN
Bgreen
CNo output
DRed
Attempts:
2 left
💡 Hint
CaseSensitive:$false makes the search ignore case.
📝 Syntax
advanced
2:00remaining
Identify the correct regex pattern syntax in Select-String
Which option correctly matches lines containing exactly three digits in a row using Select-String?
PowerShell
Select-String -Pattern '<pattern>' -Path 'numbers.txt'
A[0-9]{3}
B\d{3}
C}3{d\
D\d{,3}
Attempts:
2 left
💡 Hint
Use character classes and quantifiers correctly.
🔧 Debug
advanced
2:00remaining
Why does this Select-String command fail?
You run this command:
Select-String -Pattern '\w+@\w+\.com' -Path 'emails.txt'

But it returns no matches even though the file contains emails like 'user@example.com'. Why?
PowerShell
Select-String -Pattern '\w+@\w+\.com' -Path 'emails.txt'
ABecause the file path is incorrect
BBecause '\w' is not supported in PowerShell regex, use '[a-zA-Z0-9_]' instead
CBecause the pattern needs single quotes instead of double quotes
DBecause Select-String does not support regex
Attempts:
2 left
💡 Hint
Check if '\w' is recognized in PowerShell regex.
🚀 Application
expert
3:00remaining
Extracting matched text with Select-String and regex groups
You want to extract only the domain part from email addresses in 'emails.txt' using Select-String with regex groups. Which command correctly outputs just the domain (e.g., 'example.com')?
PowerShell
Select-String -Pattern '<pattern>' -Path 'emails.txt' | ForEach-Object { <extract> }
ASelect-String -Pattern '^[\w.-]+@([\w.-]+)$' -Path 'emails.txt' | ForEach-Object { $_.Matches.Groups[1].Value }
BSelect-String -Pattern '^[\w.-]+@([\w.-]+)$' -Path 'emails.txt' | ForEach-Object { $_.Groups[1].Value }
CSelect-String -Pattern '^[\w.-]+@([\w.-]+)$' -Path 'emails.txt' | ForEach-Object { $_.Matches[1].Groups[0].Value }
DSelect-String -Pattern '^[\w.-]+@([\w.-]+)$' -Path 'emails.txt' | ForEach-Object { $_.Matches[0].Groups[1].Value }
Attempts:
2 left
💡 Hint
Check how to access regex groups from Select-String Matches property.