code: def normalize(string, pattern=False, preserve_case=False):
      
      regex = re.compile(r'([^\s\w\(\)\[\]\|\*#])+') if pattern else re.compile(r'([^\s\w]|_)+')
  
      if not isinstance(string, string_types):
          return ''
  
      # Case folding is not supported in Python2
      try:
          string = string.strip() if preserve_case else string.strip().casefold()
      except AttributeError:
          string = string.strip() if preserve_case else string.strip().lower()
  
      return regex.sub('', string)
docs: Normalize input for comparison with other input
      :param string: The string to normalize
      :type  string: str
  
      :param pattern: Allow wildcard symbols for triggers
      :type  pattern: bool
  
      :param preserve_case: Normalize the message without casefolding
      :type  preserve_case: bool
  
      :rtype: str