code: def regex_search(self, regex: str) -> List[HistoryItem]:
          
          regex = regex.strip()
          if regex.startswith(r'/') and regex.endswith(r'/'):
              regex = regex[1:-1]
          finder = re.compile(regex, re.DOTALL | re.MULTILINE)
  
          def isin(hi):
              """filter function for doing a regular expression search of history"""
              return finder.search(hi) or finder.search(hi.expanded)
          return [itm for itm in self if isin(itm)]
docs: Find history items which match a given regular expression
  
          :param regex: the regular expression to search for.
          :return: a list of history items, or an empty list if the string was not found