import fnmatch


def _GlobToRegex(glob):
  """Converts a shell glob to a regular expression."""
  # fnmatch.translate adds '$' or '\Z(?ms)' (on python >= 2.6)
  # to the end of the regex.
  return fnmatch.translate(glob).rstrip('$').replace(r'\Z(?ms)', '')