def regex_from_ec2_regex(ec2_re):
 iter_ec2_re = iter(ec2_re)
 py_re = ''
 for char in iter_ec2_re:
  if (char == '*'):
   py_re += '.*'
  elif (char == '?'):
   py_re += '.'
  elif (char == '\\'):
   try:
    next_char = next(iter_ec2_re)
   except StopIteration:
    next_char = ''
   if ((next_char == '*') or (next_char == '?')):
    py_re += ('[%s]' % next_char)
   else:
    py_re += ('\\\\' + next_char)
  else:
   py_re += re.escape(char)
 return ('\\A%s\\Z(?s)' % py_re)

def regex_from_ec2_regex ( ec2_re ) : iter_ec2_re = iter ( ec2_re ) py_re = '' for char in iter_ec2_re : if ( char == '*' ) : py_re += '.*' elif ( char == '?' ) : py_re += '.' elif ( char == '\\' ) : try : next_char = next ( iter_ec2_re ) except StopIteration : next_char = '' if ( ( next_char == '*' ) or ( next_char == '?' ) ) : py_re += ( '[%s]' % next_char ) else : py_re += ( '\\\\' + next_char ) else : py_re += re . escape ( char ) return ( '\\A%s\\Z(?s)' % py_re )
converts an ec2-style regex to a python regex .