def regexp2pattern(string):
 if (type(string) is REGEXP_T):
  flags = string.flags
  string = string.pattern
  if string.startswith('^'):
   string = string[1:]
  else:
   string = ('.*' + string)
  if string.endswith('$'):
   string = string[:(-1)]
  else:
   string += '.*'
  return (string, flags)
 else:
  return (re.escape(string), 0)

def regexp2pattern ( string ) : if ( type ( string ) is REGEXP_T ) : flags = string . flags string = string . pattern if string . startswith ( '^' ) : string = string [ 1 : ] else : string = ( '.*' + string ) if string . endswith ( '$' ) : string = string [ : ( - 1 ) ] else : string += '.*' return ( string , flags ) else : return ( re . escape ( string ) , 0 )
this function takes a regexp or a string and returns a pattern and some flags .