Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a regex that matches the word 'cat'.
Ruby
pattern = /[1]/ Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different word inside the slashes.
Forgetting the slashes around the pattern.
✗ Incorrect
The regex literal /cat/ matches the exact string 'cat'.
2fill in blank
mediumComplete the code to check if the string 'hello' contains the letter 'e'.
Ruby
if 'hello' =~ /[1]/ puts 'Found e' end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a letter not present in the string.
Using quotes inside the regex slashes.
✗ Incorrect
The regex /e/ matches the letter 'e' in the string 'hello'.
3fill in blank
hardFix the error in the regex literal to match any digit.
Ruby
pattern = /[1]/ Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'd' without backslash matches the letter 'd', not digits.
Using square brackets or parentheses incorrectly.
✗ Incorrect
The regex /\d/ matches any digit character. The backslash must be escaped in Ruby regex literals.
4fill in blank
hardFill both blanks to create a regex that matches a word starting with 'a' and ending with 'z'.
Ruby
pattern = /[1].*[2]/
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Placing anchors in the wrong order.
Using '$z' instead of 'z$'.
✗ Incorrect
The regex /^a.*z$/ matches strings starting with 'a' and ending with 'z'.
5fill in blank
hardFill all three blanks to create a regex that matches a string with exactly three digits.
Ruby
pattern = /^[1][2][3]$/
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
\w which matches letters and digits.Using
\s which matches whitespace.✗ Incorrect
The regex /^\d\d\d$/ matches exactly three digits from start to end.