/** * Returns the string with all regex controll characters escaped.<br> * The result from this operation should return a pattern which the input string matches.<br> * WARNING: this method does not escape newline characters and for strings containing newline * characters the input will not match the result pattern.<br> * * @param input * @return */ public static String getEscaped(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); boolean escape = CharUtil.isRegexControlChar(ch); if (escape) { sb.append('\\'); } sb.append(ch); } return sb.toString(); }