0
0
PowerShellscripting~10 mins

Regex quantifiers and anchors 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 match any string that starts with 'Hello'.

PowerShell
$pattern = "[1]Hello"
Drag options to blanks, or click blank then click option'
A*
B$
C^
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ which anchors to the end of the string.
Using * or + which are quantifiers, not anchors.
2fill in blank
medium

Complete the code to match any string that ends with 'World'.

PowerShell
$pattern = "World[1]"
Drag options to blanks, or click blank then click option'
A$
B^
C?
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using ^ which anchors to the start of the string.
Using quantifiers like + or ? which do not anchor.
3fill in blank
hard

Fix the error in the regex pattern to match one or more digits.

PowerShell
$pattern = "\d[1]"
Drag options to blanks, or click blank then click option'
A*
B+
C?
D{1,}
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which means zero or more, allowing empty matches.
Using ? which means zero or one, not enough for multiple digits.
4fill in blank
hard

Fill both blanks to create a regex that matches exactly three letters at the start of a string.

PowerShell
$pattern = "[1][a-zA-Z][2]"
Drag options to blanks, or click blank then click option'
A^
B+
C{3}
D$
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ which anchors to the end instead of start.
Using + which means one or more, not exactly three.
5fill in blank
hard

Fill all three blanks to create a regex that matches a string starting with 'ID' followed by 4 to 6 digits and ending immediately.

PowerShell
$pattern = "[1]ID\d[2][3]"
Drag options to blanks, or click blank then click option'
A^
B{4,6}
C$
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which means one or more, not a range.
Missing anchors causing partial matches.