def str2regexp(string):
 if string.startswith('/'):
  string = string.split('/', 2)[1:]
  if (len(string) == 1):
   string.append('')
  string = re.compile(string[0], sum((getattr(re, f.upper()) for f in string[1])))
 return string

def str2regexp ( string ) : if string . startswith ( '/' ) : string = string . split ( '/' , 2 ) [ 1 : ] if ( len ( string ) == 1 ) : string . append ( '' ) string = re . compile ( string [ 0 ] , sum ( ( getattr ( re , f . upper ( ) ) for f in string [ 1 ] ) ) ) return string
this function takes a string and returns either this string or a python regexp object .