0
0
Bash Scriptingscripting~20 mins

Why regex enables pattern matching in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regex Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main reason regex enables pattern matching?
Why does regex allow scripts to find patterns in text effectively?
ABecause regex converts text into numbers for faster comparison
BBecause regex defines flexible rules to describe text patterns using special symbols
CBecause regex stores all text in memory for quick searching
DBecause regex uses machine learning to guess text patterns
Attempts:
2 left
💡 Hint
Think about how regex uses symbols like * and ? to match text.
💻 Command Output
intermediate
2: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
A
application
banana
Bbanana
Capple
D
apple
application
Attempts:
2 left
💡 Hint
The regex '^app.*' matches lines starting with 'app'.
📝 Syntax
advanced
2: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.
A'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
B'[a-z]+@[a-z]+\.[a-z]+'
C'^\w+@\w+\.\w{2,3}$'
D'[a-zA-Z]+@[0-9]+\.[a-z]{2,}'
Attempts:
2 left
💡 Hint
Look for a pattern that allows letters, numbers, dots, and special characters before and after '@'.
🔧 Debug
advanced
2: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$'
AThe caret '^' is misplaced and should be at the end
BThe dot '.' is not escaped properly, so it matches any character
CThe '+' symbol is not recognized by grep without -E option, causing no match
DThe brackets [] are used incorrectly for digits
Attempts:
2 left
💡 Hint
Basic grep does not support '+' quantifier without extra flags.
🚀 Application
expert
3: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?
Agrep -oE '\b[0-9]{4}-[0-9]{2}-[0-9]{2}\b' log.txt
Bgrep '\d{4}-\d{2}-\d{2}' log.txt
Cgrep -E '[0-9]{4}/[0-9]{2}/[0-9]{2}' log.txt
Dgrep -o '[0-9]{4}-[0-9]{2}-[0-9]{2}' log.txt
Attempts:
2 left
💡 Hint
Use extended regex and word boundaries to match exact date format.