SQLSafe { static String cleanRegexpTerm(final String value) { if (value != null) { return value.replaceAll("([\\\\\\.\\[\\{\\(\\)\\*\\+\\?\\^\\$\\|])", "\\\\$1"); } else { return value; } } private  SQLSafe();   }
@Test void testRegexTerm() { final String dirty = "abc\\^$.|?*+()[{def"; final String expected = "abc\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{def"; final String cleaned = SQLSafe.cleanRegexpTerm(dirty); System.out.println(dirty); System.out.println(cleaned); assertThat(cleaned).isEqualTo(expected); }