String (@NotNull String regexp) { final StringBuilder result = new StringBuilder(); for (int i = 0, length = regexp.length(); i < length; i++) { final int c = regexp.codePointAt(i); if (c == '.') { if (i == length - 1 || !MatchUtil.isRegExpMetaChar(regexp.codePointAt(i + 1))) { result.append('.'); // consider dot not followed by other meta char a mistake } else { return ""; // can't convert } } else if (c == '|') { result.append('|'); } else if (c == '\\') { if (i + 1 < length) { result.appendCodePoint(regexp.codePointAt(i + 1)); i++; } else { result.append('\\'); } } else if (c == ']') { result.append(']'); } else if (c == '(' || c == ')') { // do nothing } else if (MatchUtil.isRegExpMetaChar(c)) { return ""; // can't convert } else { result.appendCodePoint(c); } } return result.toString(); }