Recall & Review
beginner
What is a regex literal in Ruby?
A regex literal in Ruby is a pattern written between slashes, like
/pattern/, used to match text.Click to reveal answer
beginner
How do you write a regex literal to match the word 'cat' exactly?
You write
/cat/. This matches the exact sequence of characters 'cat' anywhere in the text.Click to reveal answer
intermediate
What does the regex literal
/\d+/ match?It matches one or more digits in a row.
\d means any digit, and + means one or more times.Click to reveal answer
intermediate
How do you include options like case-insensitive matching in a regex literal?
Add a letter after the closing slash. For example,
/cat/i matches 'cat', 'Cat', or 'CAT'.Click to reveal answer
intermediate
How do you write a regex literal to match a string that starts with 'hello'?
Use the caret symbol
^ at the start: /^hello/. This matches 'hello' only at the beginning of the text.Click to reveal answer
What does the regex literal
/ruby/ match?✗ Incorrect
The regex literal
/ruby/ matches the exact sequence 'ruby' anywhere in the text, case-sensitive.How do you write a regex literal to match one or more digits?
✗ Incorrect
\d matches digits, and + means one or more times.What does the
i after a regex literal do? For example, /cat/i✗ Incorrect
The
i flag makes the regex ignore case differences.Which regex literal matches a string that starts with 'hello'?
✗ Incorrect
The caret
^ means the start of the string.How do you write a regex literal to match a newline character?
✗ Incorrect
\n matches a newline character.Explain how to write a regex literal in Ruby and how to add options like case-insensitivity.
Think about the slashes and letters after them.
You got /4 concepts.
Describe how anchors like ^ and $ work inside regex literals.
Anchors fix where the match happens.
You got /3 concepts.