static private int countOpenParens(String s, int pos) {
        java.util.regex.Pattern p = java.util.regex.Pattern.compile("\\(");
        java.util.regex.Matcher m = p.matcher(s.subSequence(0, pos));

        int numParens = 0;

        while (m.find()) {
            // ignore parentheses inside character classes: [0-9()a-f]
            // which are just literals
            if (isInsideCharClass(s, m.start())) {
                continue;
            }

            // ignore escaped parens
            if (isEscapedChar(s, m.start())) continue;

            if (!isNoncapturingParen(s, m.start())) {
                numParens++;
            }
        }
        return numParens;
    }
static private int countOpenParens(String s, int pos) {
        java.util.regex.Pattern p = java.util.regex.Pattern.compile("\\(");
        java.util.regex.Matcher m = p.matcher(s.subSequence(0, pos));

        int numParens = 0;

        while (m.find()) {
            
            
            if (isInsideCharClass(s, m.start())) {
                continue;
            }

            
            if (isEscapedChar(s, m.start())) continue;

            if (!isNoncapturingParen(s, m.start())) {
                numParens++;
            }
        }
        return numParens;
    }
static private int countOpenParens ( String s , int pos ) { java . util . regex . Pattern p = java . util . regex . Pattern . compile ( "\\(" ) ; java . util . regex . Matcher m = p . matcher ( s . subSequence ( 0 , pos ) ) ; int numParens = 0 ; while ( m . find ( ) ) { // ignore parentheses inside character classes: [0-9()a-f] // which are just literals if ( isInsideCharClass ( s , m . start ( ) ) ) { continue ; } // ignore escaped parens if ( isEscapedChar ( s , m . start ( ) ) ) continue ; if ( ! isNoncapturingParen ( s , m . start ( ) ) ) { numParens ++ ; } } return numParens ; }
Counts the open-parentheses to the left of a string position,
excluding escaped parentheses

@param s string to evaluate
@param pos ending position of string; characters to the left
of this position are evaluated
@return number of open parentheses
Counts the open - parentheses to the left of a string position excluding escaped parentheses