code: def fnmatch_pathname_to_regex(pattern):
  	
  	i, n = 0, len(pattern)
  	nonsep = ''.join(['[^', os.sep, ']'])
  	res = []
  	while i < n:
  		c = pattern[i]
  		i = i + 1
  		if c == '*':
  			try:
  				if pattern[i] == '*':
  					i = i + 1
  					res.append('.*')
  					if pattern[i] == '/':
  						i = i + 1
  						res.append(''.join([os.sep, '?']))
  				else:
  					res.append(''.join([nonsep, '*']))
  			except IndexError:
  				res.append(''.join([nonsep, '*']))
  		elif c == '?':
  			res.append(nonsep)
  		elif c == '/':
  			res.append(os.sep)
  		elif c == '[':
  			j = i
  			if j < n and pattern[j] == '!':
  				j = j + 1
  			if j < n and pattern[j] == ']':
  				j = j + 1
  			while j < n and pattern[j] != ']':
  				j = j+1
  			if j >= n:
  				res.append('\\[')
  			else:
  				stuff = pattern[i:j].replace('\\', '\\\\')
  				i = j+1
  				if stuff[0] == '!':
  					stuff = ''.join('^', stuff[1:])
  				elif stuff[0] == '^':
  					stuff = ''.join('\\' + stuff)
  				res.append('[{}]'.format(stuff))
  		else:
  			res.append(re.escape(c))
  	res.insert(0, '(?ms)')
  	res.append('\Z')
  	return ''.join(res)
docs: Implements fnmatch style-behavior, as though with FNM_PATHNAME flagged;
  	the path seperator will not match shell-style '*' and '.' wildcards.