def glob_to_regex(pattern):
    """Convert a 'glob' pattern for file name matching to a regular
    expression. E.g. "foo.? bar*" -> "foo\.. \bar.*" """
    return "^"+pattern.replace(".","\.").replace("*",".*").replace("?",".")+"$"