private static void checkRegexp(String regexp) {
        String checking = regexp.replaceAll("\\\\\\(", "X").replaceAll("\\(\\?", "X");
        int checked = checking.indexOf('(');
        if (checked > -1) {
            StringBuilder msg = new StringBuilder("Only non-capturing groups allowed:\r\n" +
                    regexp + "\r\n");
            for (int i = 0; i < checked; i++) {
                msg.append(" ");
            }
            msg.append("^");
            throw new IllegalArgumentException(msg.toString());
        }
    }
private static void checkRegexp ( String regexp ) { String checking = regexp . replaceAll ( "\\\\\\(" , "X" ) . replaceAll ( "\\(\\?" , "X" ) ; int checked = checking . indexOf ( '(' ) ; if ( checked > - 1 ) { StringBuilder msg = new StringBuilder ( "Only non-capturing groups allowed:\r\n" + regexp + "\r\n" ) ; for ( int i = 0 ; i < checked ; i ++ ) { msg . append ( " " ) ; } msg . append ( "^" ) ; throw new IllegalArgumentException ( msg . toString ( ) ) ; } }
Ensures not adding any regexp with capturing groups