Case insensitive and pattern matching

This replaces pull request #1751. This is for issue #1724.
Might make sense to rename this to `_glob_pattern_to_regexp` or something similar.