Challenge - 5 Problems
Regex Match Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Nginx regex match case sensitivity
Given the following nginx location block, what type of requests will it match?
location ~* ".*\.jpg$" { return 200; }Attempts:
2 left
💡 Hint
The ~* operator means case insensitive regex match.
✗ Incorrect
The ~* operator in nginx means a case-insensitive regex match. The pattern ".*\.jpg$" matches any URL ending with .jpg or .JPG or any case variant.
💻 Command Output
intermediate2:00remaining
Nginx regex match case sensitivity difference
What is the difference in matching behavior between these two nginx location blocks?
location ~ ".*\.css$" { return 200; }
location ~* ".*\.css$" { return 200; }Attempts:
2 left
💡 Hint
Check the difference between ~ and ~* operators.
✗ Incorrect
The ~ operator is case sensitive regex match, so it matches only lowercase .css. The ~* operator is case insensitive, so it matches .css, .CSS, .Css, etc.
❓ Troubleshoot
advanced2:00remaining
Why does this nginx regex location not match uppercase extensions?
You have this nginx config:
You notice requests for image.PNG return 404. Why?
location ~ ".*\.png$" { return 200; }You notice requests for image.PNG return 404. Why?
Attempts:
2 left
💡 Hint
Consider the difference between ~ and ~* in nginx.
✗ Incorrect
The ~ operator performs a case sensitive match. So .PNG does not match ".*\.png$". To match uppercase extensions, use ~*.
✅ Best Practice
advanced2:00remaining
Choosing regex match operator for nginx location
Which nginx location regex operator is best to match URLs ending with .html or .HTML regardless of case?
Attempts:
2 left
💡 Hint
Think about case sensitivity and regex matching.
✗ Incorrect
The ~* operator performs case-insensitive regex matching, so it matches .html and .HTML. The ~ operator is case sensitive. = is exact match, and prefix match does not support regex.
🧠 Conceptual
expert2:00remaining
Understanding nginx regex match precedence
Given these nginx location blocks:
What happens when a request for /images/photo.JPG is made?
location /images/ {
return 404;
}
location ~* ".*\.jpg$" {
return 200;
}What happens when a request for /images/photo.JPG is made?
Attempts:
2 left
💡 Hint
Nginx chooses regex locations over prefix if regex matches.
✗ Incorrect
Nginx first finds the longest prefix match (/images/), then checks regex locations. If a regex location matches, it takes precedence over prefix. So /images/photo.JPG matches the regex location and returns 200.