function getRegexForBracketPair(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);
}
Create a regular expression that can be used to search forward in a piece of text
for a group of bracket pairs. But this regex must be built in a way in which
it is aware of the other bracket pairs defined for the language.

For example, if a language contains the following bracket pairs:
  ['begin', 'end']
  ['if', 'end if']
The two bracket pairs do not collide because no open or close brackets are equal.
So the function getRegexForBracketPair is called twice, once with
the ['begin'], ['end'] group consisting of one bracket pair, and once with
the ['if'], ['end if'] group consiting of the other bracket pair.

But there could be a situation where an occurrence of 'end if' is mistaken
for an occurrence of 'end'.

Therefore, for the bracket pair ['begin', 'end'], the regex will also
target 'end if'. The regex will be something like:
  /(\bend if\b)|(\bend\b)|(\bif\b)/

The regex also searches for "superstrings" (other brackets that might be mistaken with the current bracket).