code: def split_by_regex(self, regex_or_pattern, flags=re.U, gaps=True):
          
  
          text = self[TEXT]
          regex = regex_or_pattern
          if isinstance(regex, six.string_types):
              regex = re.compile(regex_or_pattern, flags=flags)
          # else is assumed pattern
          last_end = 0
          spans = []
          if gaps: # tag cap spans
              for mo in regex.finditer(text):
                  start, end = mo.start(), mo.end()
                  if start > last_end:
                      spans.append((last_end, start))
                  last_end = end
              if last_end < len(text):
                  spans.append((last_end, len(text)))
          else: # use matched regions
              spans = [(mo.start(), mo.end()) for mo in regex.finditer(text)]
          return self.split_given_spans(spans)
docs: Split the text into multiple instances using a regex.
  
          Parameters
          ----------
          regex_or_pattern: str or compiled pattern
              The regular expression to use for splitting.
          flags: int (default: re.U)
              The regular expression flags (only used, when user has not supplied compiled regex).
          gaps: boolean (default: True)
              If True, then regions matched by the regex are not included in the resulting Text instances, which
              is expected behaviour.
              If False, then only regions matched by the regex are included in the result.
  
          Returns
          -------
          list of Text
              The Text instances obtained by splitting.