What is the difference between Nginx ~ and ~* regexes?

What is the difference between Nginx ~ and ~* regexes?

For example:

if ($http_referer ~* www.foobar.net) {
    ...
}

vs

if ($http_referer ~ www.foobar.net) {
    ...
}

Solution 1:

~: If a tilde modifier is present, this location will be interpreted as a case-sensitive regular expression match.

~*: If a tilde and asterisk modifier is used, the location block will be interpreted as a case-insensitive regular expression match.

Solution 2:

cduffin is correct.

Here is an example of using this regex for a location block to reject uri's that try to access a certain file type (assuming we are using try_files lower in the nginx config)

location ~* \.(txt|log|config)$ {
    return 403;
}