PatternUtils { public static boolean isRegex(String expression) { try { Pattern.compile(expression); return true; } catch (Exception e) { return false; } }  static boolean isExactMatch(String expression); static boolean isContainsMatch(String expression); static boolean isRegex(String expression); static String removeFirstAndLastChars(String expression);  }
@Test public void testIsRegex() { assertThat(isRegex("regex.*"), is(true)); assertThat(isRegex("(wrong"), is(false)); }