Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a string contains only digits using regex.
PowerShell
$string = "12345" if ($string -match "^[1]$") { Write-Output "Only digits" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using \w+ matches letters and digits, not digits only.
Using \s+ matches whitespace, not digits.
✗ Incorrect
The pattern \d+ matches one or more digits. Anchors ^ and $ ensure the entire string is digits only.
2fill in blank
mediumComplete the code to find all words starting with a capital letter.
PowerShell
$text = "Hello World from PowerShell" $matches = [regex]::Matches($text, "\b[1]\w*") $matches | ForEach-Object { $_.Value }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [a-z] matches lowercase letters, not capital letters.
Using \d matches digits, not letters.
✗ Incorrect
The pattern [A-Z] matches any uppercase letter at the start of a word boundary \b.
3fill in blank
hardFix the error in the regex pattern to match email addresses.
PowerShell
$email = "user@example.com" if ($email -match "^[\w.-]+@[1]\.[a-z]{2,}$") { Write-Output "Valid email" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [\d]+ matches only digits, not domain names.
Using [\s]+ matches spaces, invalid in emails.
✗ Incorrect
The pattern [\w-]+ matches the domain part of the email (letters, digits, underscore, hyphen).
4fill in blank
hardFill both blanks to create a regex that matches a US phone number format (e.g., 123-456-7890).
PowerShell
$phone = "123-456-7890" if ($phone -match "^[1]-[2]-\d{4}$") { Write-Output "Valid phone number" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using \w{3} matches letters and digits, not just digits.
Using \s{3} matches spaces, not digits.
✗ Incorrect
The pattern \d{3} matches exactly three digits for the first two parts of the phone number.
5fill in blank
hardFill both blanks to create a regex that matches a hex color code (e.g., #1A2B3C).
PowerShell
$color = "#1A2B3C" if ($color -match "^[1][2]$") { Write-Output "Valid hex color" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [A-Fa-f0-9]{3} matches only 3 digits, not 6.
Missing the # at the start.
✗ Incorrect
The pattern starts with #, followed by 6 hex digits ([0-9A-Fa-f]{6}).