Challenge - 5 Problems
Extended Regex Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of grep -E with alternation
What is the output of this command when run on a file containing these lines:
Command:
apple banana apricot blueberry blackberry
Command:
grep -E 'ap|bl' filename
Bash Scripting
grep -E 'ap|bl' filenameAttempts:
2 left
💡 Hint
Look for lines containing either 'ap' or 'bl' anywhere in the line.
✗ Incorrect
The pattern 'ap|bl' matches lines containing 'ap' or 'bl'. 'apple' and 'apricot' contain 'ap', 'blueberry' and 'blackberry' contain 'bl'. 'banana' does not match.
💻 Command Output
intermediate2:00remaining
Using grep -E with character classes
Given a file with these lines:
What is the output of:
cat cot cut cit cet
What is the output of:
grep -E 'c[aeiou]t' filename
Bash Scripting
grep -E 'c[aeiou]t' filenameAttempts:
2 left
💡 Hint
The character class [aeiou] matches any vowel.
✗ Incorrect
The pattern matches lines starting with 'c', then a vowel (a,e,i,o,u), then 't'. All lines have 'c' + vowel + 't', so all lines match.
💻 Command Output
advanced2:00remaining
Output of grep -E with quantifiers
What is the output of this command on a file with these lines:
Command:
aaa aa aaaa a aaaaa
Command:
grep -E 'a{3,4}' filenameBash Scripting
grep -E 'a{3,4}' filenameAttempts:
2 left
💡 Hint
The pattern matches sequences of 'a' repeated 3 or 4 times anywhere in the line.
✗ Incorrect
Lines with at least 3 consecutive 'a's match. 'aaa', 'aaaa', and 'aaaaa' contain such sequences. 'aa' and 'a' do not.
💻 Command Output
advanced2:00remaining
grep -E with anchors and groups
Given a file with these lines:
What is the output of:
foo123 123foo foo456 bar123foo foo
What is the output of:
grep -E '^foo[0-9]+$' filename
Bash Scripting
grep -E '^foo[0-9]+$' filenameAttempts:
2 left
💡 Hint
The pattern matches lines starting with 'foo' and ending with one or more digits.
✗ Incorrect
Only lines starting with 'foo' and followed by digits until end match: 'foo123' and 'foo456'. 'foo' alone has no digits, others don't start with 'foo' or have extra chars.
💻 Command Output
expert2:00remaining
Complex pattern with grep -E and lookalike syntax
What error or output results from running this command on any file?
grep -E '(?<=foo)bar' filename
Bash Scripting
grep -E '(?<=foo)bar' filenameAttempts:
2 left
💡 Hint
grep -E does not support lookbehind assertions like (?<=...).
✗ Incorrect
The '(?<=foo)' is a lookbehind assertion not supported by grep -E, causing a regex syntax error.