code: def re_escape(pattern, chars=frozenset("()[]{}?*+|^$\\.-#")):
      '''
      Escape all special regex characters in pattern.
      Logic taken from regex module.
  
      :param pattern: regex pattern to escape
      :type patterm: str
      :returns: escaped pattern
      :rtype: str
      '''
      escape = '\\{}'.format
      return ''.join(
          escape(c) if c in chars or c.isspace() else
          '\\000' if c == '\x00' else c
          for c in pattern
          f re_escape(pattern, chars=frozenset("()[]{}?*+|^$\\.-#")):
      '''
      Escape all special regex characters in pattern.
      Logic taken from regex module.
  
      :param pattern: regex pattern to escape
      :type patterm: str
      :returns: escaped pattern
      :rtype: str
      '''
      escape = '\\{}'.format
      return ''.join(
          escape(c) if c in chars or c.isspace() else
          '\\000' if c == '\x00' else c
          for c in pattern
          )
docs: Escape all special regex characters in pattern.
      Logic taken from regex module.
  
      :param pattern: regex pattern to escape
      :type patterm: str
      :returns: escaped pattern
      :rtype: str