function split(exp, text, acc) {
    /**
     * Get the next match starting from the end of the last match or start of
     * string.
     */
    const match = exp.exec(text);
    const lastEntry = last(acc);

    /**
     * `match` will be null if there are no matches.
     */
    if (!match) return acc;

    /**
     * If the match is at the beginning of the input string, normalize to a data
     * object with the `match` flag set to `true`, and add to the accumulator.
     */
    if (match.index === 0) {
      addSubstring(acc, 0, match[0], true);
    } else if (!lastEntry) {
      /**
       * If there are no entries in the accumulator, convert the substring before
       * the match to a data object (without the `match` flag set to true) and
       * push to the accumulator, followed by a data object for the matching
       * substring.
       */
      addSubstring(acc, 0, match.input.slice(0, match.index));
      addSubstring(acc, match.index, match[0], true);
    } else if (match.index === lastEntry.index + lastEntry.text.length) {
      /**
       * If the last entry in the accumulator immediately preceded the current
       * matched substring in the original string, just add the data object for
       * the matching substring to the accumulator.
       */
      addSubstring(acc, match.index, match[0], true);
    } else {
      /**
       * Convert the substring before the match to a data object (without the
       * `match` flag set to true), followed by a data object for the matching
       * substring.
       */
      const nextIndex = lastEntry.index + lastEntry.text.length;
      const nextText = match.input.slice(nextIndex, match.index);
      addSubstring(acc, nextIndex, nextText);
      addSubstring(acc, match.index, match[0], true);
    }

    /**
     * Continue executing the expression.
     */
    return split(exp, text, acc);
  }
Splits the string into an array of objects with the following shape:

{
  index: number - the index of the substring within the string
  text: string - the substring
  match: boolean - true if the substring matched `matchPattern`
}

Loops through matches via recursion (`RegExp.exec` tracks the loop
internally).