Recall & Review
beginner
What does the caret (^) anchor mean in a regular expression?
The caret (^) anchor means the pattern must match at the start of a line or string.
Click to reveal answer
beginner
What does the dollar sign ($) anchor mean in a regular expression?
The dollar sign ($) anchor means the pattern must match at the end of a line or string.
Click to reveal answer
beginner
In bash scripting, how would you use ^ and $ to match a line that exactly contains 'hello'?
Use the pattern '^hello$' to match lines that contain only 'hello' with nothing before or after.
Click to reveal answer
intermediate
Why are anchors useful in scripting when searching text?
Anchors help ensure you match text only at the start or end of lines, avoiding partial matches inside lines.
Click to reveal answer
beginner
What happens if you omit anchors in a regex pattern in bash?
Without anchors, the pattern can match anywhere in the line, which may lead to unexpected matches.
Click to reveal answer
What does the regex pattern '^abc' match?
✗ Incorrect
The caret (^) means the pattern must be at the start of the line.
What does the regex pattern 'xyz$' match?
✗ Incorrect
The dollar sign ($) means the pattern must be at the end of the line.
Which pattern matches a line that contains only 'test' and nothing else?
✗ Incorrect
Using both ^ and $ anchors ensures the entire line is exactly 'test'.
If you want to find lines that contain 'data' anywhere, which pattern should you use?
✗ Incorrect
No anchors means 'data' can appear anywhere in the line.
What is the effect of using anchors in a grep command?
✗ Incorrect
Anchors restrict matches to line beginnings (^) or ends ($).
Explain how the ^ and $ anchors work in regular expressions and why they are useful in bash scripting.
Think about matching only at the start or end of a line.
You got /4 concepts.
Describe a real-life example where using ^ and $ anchors in a bash script would help you find exactly what you want.
Imagine searching a list for an exact name, not just part of it.
You got /4 concepts.