code: function findEndPattern(text, offset, delta) {
          var patterns, pattern, i;
  
          // Find best matching end
          patterns = getPatterns();
          for (i = 0; i < patterns.length; i++) {
            pattern = patterns[i];
            if (pattern.end && text.substr(offset - pattern.end.length - delta, pattern.end.length) == pattern.end) {
              return pattern;
            }
          }
        }
docs: Finds the best matching end pattern