String (int offset, int startOffset, ElementPattern<Character> idPart, ElementPattern<Character> idStart, CharSequence text) { final int offsetInElement = offset - startOffset; int start = offsetInElement - 1; while (start >=0) { if (!idPart.accepts(text.charAt(start))) break; --start; } while (start + 1 < offsetInElement && !idStart.accepts(text.charAt(start + 1))) { start++; } return text.subSequence(start + 1, offsetInElement).toString().trim(); }