0
0
PowerShellscripting~10 mins

Regex with Select-String in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to search for the word 'error' in the file 'log.txt'.

PowerShell
Select-String -Path 'log.txt' -Pattern '[1]'
Drag options to blanks, or click blank then click option'
Ainfo
Bwarning
Cerror
Ddebug
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes.
Searching for a word not present in the file.
2fill in blank
medium

Complete the code to search for lines that start with 'Error' in 'log.txt'.

PowerShell
Select-String -Path 'log.txt' -Pattern '[1]'
Drag options to blanks, or click blank then click option'
A^Error
BError$
CError
D^error$
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$' which matches end of line instead of start.
Not using anchors and matching anywhere in the line.
3fill in blank
hard

Fix the error in the code to find lines containing digits in 'data.txt'.

PowerShell
Select-String -Path 'data.txt' -Pattern '[1]'
Drag options to blanks, or click blank then click option'
A\w+
B\d+
C[0-9]+
D[a-z]+
Attempts:
3 left
💡 Hint
Common Mistakes
Using single backslash '\d' which is not escaped properly.
Using character classes that do not match digits.
4fill in blank
hard

Fill both blanks to find lines with exactly 3 letters followed by 2 digits in 'file.txt'.

PowerShell
Select-String -Path 'file.txt' -Pattern '[1][2]'
Drag options to blanks, or click blank then click option'
A^[a-zA-Z]{3}
B\d{2}$
C\d{3}$
D^[0-9]{3}
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of letters and digits.
Using wrong quantifiers for number of characters.
5fill in blank
hard

Fill all three blanks to find lines containing a word starting with 'a' and ending with 'z' in 'text.txt'.

PowerShell
Select-String -Path 'text.txt' -Pattern '[1][2][3]'
Drag options to blanks, or click blank then click option'
A\ba
B.*
Cz\b
D\w+
Attempts:
3 left
💡 Hint
Common Mistakes
Not using word boundaries '\b'.
Using '+' instead of '*' causing no match for empty middle.