function getReversedRegexForBracketPair(open, close, brackets, currentIndex) {
    // search in all brackets for other brackets that are a superstring of these brackets
    let pieces = [];
    pieces = pieces.concat(open);
    pieces = pieces.concat(close);
    for (let i = 0, len = pieces.length; i < len; i++) {
        collectSuperstrings(pieces[i], brackets, currentIndex, pieces);
    }
    pieces = unique(pieces);
    pieces.sort(lengthcmp);
    pieces.reverse();
    return createBracketOrRegExp(pieces.map(toReversedString));
}
Matching a regular expression in JS can only be done "forwards". So JS offers natively only
methods to find the first match of a regex in a string. But sometimes, it is useful to
find the last match of a regex in a string. For such a situation, a nice solution is to
simply reverse the string and then search for a reversed regex.

This function also has the fine details of `getRegexForBracketPair`. For the same example
given above, the regex produced here would look like:
  /(\bfi dne\b)|(\bdne\b)|(\bfi\b)/