public static String escape ( String input , char echar , char [ ] special ) { StringBuilder sb = new StringBuilder ( ) ; for ( Character character : special ) { sb . append ( character ) ; } sb . append ( echar ) ; String s = Matcher . quoteReplacement ( new String ( new char [ ] { echar } ) ) ; return input . replaceAll ( "[" + Pattern . quote ( sb . toString ( ) ) + "]" , s + "$0" ) ; }
Escape the input string using the escape delimiter for the given special chars