Challenge - 5 Problems
Regex Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find names starting with 'A' or 'a'
Given a table users with a column
name, which query returns all users whose names start with the letter 'A' or 'a' using the regular expression match operator?PostgreSQL
SELECT name FROM users WHERE name ~ '^[Aa]';
Attempts:
2 left
💡 Hint
Remember that ~ is case-sensitive and ^ means start of string.
✗ Incorrect
Option C uses ~ with a regex that matches names starting with either uppercase or lowercase A. Option C uses ~* which is case-insensitive but without ^ matches 'a' anywhere. Option C uses LIKE which is not regex. Option C matches only lowercase 'a' at start.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in regex query
Which of the following queries will cause a syntax error due to incorrect regular expression syntax?
Attempts:
2 left
💡 Hint
Check for balanced brackets in the regex pattern.
✗ Incorrect
Option D has an unbalanced bracket in the regex pattern causing a syntax error. The others have valid regex patterns.
❓ optimization
advanced2:00remaining
Optimize regex for case-insensitive matching
You want to find all rows where the column
title contains the word 'data' regardless of case. Which query is the most efficient and correct way to do this using PostgreSQL regex operators?Attempts:
2 left
💡 Hint
~* is the case-insensitive regex match operator.
✗ Incorrect
Option A uses ~* for case-insensitive regex and word boundaries \m and \M to match whole word 'data'. Option A is case-sensitive. Option A uses ILIKE which is not regex. Option A converts to lowercase but uses case-sensitive regex.
🔧 Debug
advanced2:00remaining
Debug why regex query returns no rows
A user runs this query but gets no results:
SELECT * FROM employees WHERE email ~ '^\w+@company\.com$'; The emails are stored in mixed case and look like 'John@Company.com'. Why might this query return no rows?Attempts:
2 left
💡 Hint
The ~ operator is case-sensitive.
✗ Incorrect
The ~ operator performs case-sensitive regex matching. The pattern expects lowercase 'company' but emails have 'Company' with uppercase 'C', causing no matches. The other options are incorrect: ~ supports regex, anchors are present, and backslashes are properly handled.
🧠 Conceptual
expert2:00remaining
Understanding difference between ~ and ~* operators
Which statement best describes the difference between the PostgreSQL operators
~ and ~*?Attempts:
2 left
💡 Hint
Think about case sensitivity in regex matching.
✗ Incorrect
The ~ operator matches regex patterns with case sensitivity. The ~* operator matches regex patterns ignoring case differences.