function getReversedRegexForBrackets(brackets) {
    let pieces = [];
    for (const bracket of brackets) {
        for (const open of bracket.open) {
            pieces.push(open);
        }
        for (const close of bracket.close) {
            pieces.push(close);
        }
    }
    pieces = unique(pieces);
    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.

e.g. for the bracket pairs:
 ['{','}']
 ['begin,'end']
 ['for','end']
the regex would look like:
 /(\{)|(\})|(\bnigeb\b)|(\bdne\b)|(\brof\b)/