String (@NotNull String sentence) { int i = sentence.indexOf(". "); while (i >= 0) { String egText = ", e.g."; if (!sentence.regionMatches(i - egText.length() + 1, egText, 0, egText.length())) { return sentence.substring(0, i + 1); } i = sentence.indexOf(". ", i + 1); } return sentence; }