Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable 'text' contains the word 'hello' using regex.
Bash Scripting
if [[ $text =~ [1] ]]; then echo "Match found"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using anchors like ^ or $ which restrict the match to start or end of the string.
Using patterns that match numbers instead of the word 'hello'.
✗ Incorrect
The regex "hello" matches the exact word 'hello' anywhere in the text.
2fill in blank
mediumComplete the code to match any string that starts with 'file' followed by digits.
Bash Scripting
if [[ $filename =~ [1] ]]; then echo "Valid file name"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' which means zero or more digits, allowing 'file' alone.
Using anchors that restrict the match to the whole string.
✗ Incorrect
The regex "file[0-9]+" matches 'file' followed by one or more digits anywhere in the string.
3fill in blank
hardFix the error in the regex to match an email address in the variable 'email'.
Bash Scripting
if [[ $email =~ [1] ]]; then echo "Valid email"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single backslash which is not enough inside double quotes.
Not escaping the dot, causing it to match any character.
✗ Incorrect
In bash regex, the dot must be escaped with double backslash \\ to match a literal dot.
4fill in blank
hardFill both blanks to create a regex that matches strings starting with 'log' and ending with '.txt'.
Bash Scripting
if [[ $filename =~ [1] && $filename =~ [2] ]]; then echo "Log file detected"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using anchors '^' and '$' to specify start and end.
Not escaping the dot in '.txt'.
✗ Incorrect
The first regex '^log' matches strings starting with 'log'. The second '\.txt$' matches strings ending with '.txt'.
5fill in blank
hardFill all three blanks to create a regex that matches a date in 'YYYY-MM-DD' format.
Bash Scripting
if [[ $date =~ ^[1]-[2]-[3]$ ]]; then echo "Valid date format"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect digit counts for year.
Not restricting month and day to valid ranges.
✗ Incorrect
The regex matches 4 digits for year, then a month between 01-12, then a day between 01-31.