Challenge - 5 Problems
Regex Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What is the main reason regex enables pattern matching?
Why does regex allow scripts to find patterns in text effectively?
Attempts:
2 left
💡 Hint
Think about how regex uses symbols like * and ? to match text.
✗ Incorrect
Regex uses special characters to describe patterns, letting scripts match complex text sequences easily.
💻 Command Output
intermediate2:00remaining
What is the output of this grep command using regex?
Given a file 'data.txt' with lines: 'apple', 'application', 'banana', what does this command output?
grep '^app.*' data.txt
Bash Scripting
apple application banana
Attempts:
2 left
💡 Hint
The regex '^app.*' matches lines starting with 'app'.
✗ Incorrect
The caret ^ means start of line, 'app' matches those letters, and '.*' matches any characters after, so both 'apple' and 'application' match.
📝 Syntax
advanced2:00remaining
Which regex pattern correctly matches an email address in bash?
Choose the regex pattern that matches a simple email format like 'user@example.com' in bash scripts.
Attempts:
2 left
💡 Hint
Look for a pattern that allows letters, numbers, dots, and special characters before and after '@'.
✗ Incorrect
Option A uses a common regex for emails allowing letters, digits, dots, and special chars before '@', domain name after, and a dot with 2+ letters for TLD.
🔧 Debug
advanced2:00remaining
Why does this regex fail to match 'file123.txt'?
The regex '^file[0-9]+\.txt$' is used but does not match 'file123.txt'. What is the likely cause?
Bash Scripting
echo 'file123.txt' | grep '^file[0-9]+\.txt$'
Attempts:
2 left
💡 Hint
Basic grep does not support '+' quantifier without extra flags.
✗ Incorrect
In basic grep, '+' is treated as a literal plus sign. To use '+' as 'one or more', grep needs the -E flag for extended regex.
🚀 Application
expert3:00remaining
How to extract all dates in YYYY-MM-DD format from a text file using bash regex?
You want to find all dates like '2023-06-15' in a file 'log.txt'. Which command correctly extracts these dates?
Attempts:
2 left
💡 Hint
Use extended regex and word boundaries to match exact date format.
✗ Incorrect
Option A uses -E for extended regex, -o to output only matches, and '\b' for word boundaries to match dates exactly.