private static String escapeQuotedSubstring ( String input ) { String [ ] parts = input . split ( "'" ) ; StringBuilder output = new StringBuilder ( input . length ( ) * 2 ) ; for ( int i = 0 ; i < parts . length ; i ++ ) { if ( ( i % 2 ) == 1 ) { output . append ( "'" ) . append ( parts [ i ] . replace ( "|" , "\\|" ) ) . append ( "'" ) ; } else { output . append ( parts [ i ] ) ; } } return output . toString ( ) ; }
Add backslash to escape the | character within quoted sections of the input string . This prevents the | from being processed as part of a regex .