Matcher (FindModel model, CharSequence text, int startOffset) { Matcher matcher = compileRegExp(model, text); assert matcher != null; if (model.isForward()) { if (!matcher.find(startOffset)) { return null; } if (matcher.end() > text.length()) { return null; } } else { int start = -1; while(matcher.find() && matcher.end() < startOffset) { start = matcher.start(); } if (start < 0) { return null; } } return matcher; }